Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7802225
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T01:11:53+00:00 2026-06-02T01:11:53+00:00

I wrote a R function to return rows satisfying specific requirements, but I got

  • 0

I wrote a R function to return rows satisfying specific requirements, but I got problem with output format.

For example, return rows with certain values:

xx.1 <- data.frame(aa= 1:5, bb = c("AA","BB","CC","DD","EE"))
xx.2 <- c("AA","DD")
ff_in <- function(x,y){
  if (toupper(x[2]) %in% y) {return(x)}
}
apply(xx.1,1,ff_in,xx.2)

However, the output looks like :

[[1]]
aa   bb 
"1" "AA" 

[[2]]
NULL

[[3]]
NULL

[[4]]
aa   bb 
"4" "DD" 

[[5]]
NULL

How to suppress R return null, and return something likes this?

aa bb
"1" "AA" 
"4" "DD" 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T01:11:55+00:00Added an answer on June 2, 2026 at 1:11 am

    Wouldn’t it be easier to just do:

    xx.1[ toupper(xx.1[[2]]) %in% xx.2 , ]
    

    If you needed it in a function, I’m sure this would be faster and would also not have the undesirable side-effect of coercion of a dataframe to a character matrix.

    exncol <- function(df, coln, choices) df[ toupper(df[[coln]]) %in% choices , ]
    exncol(xx.1, 2, xx.2)
      aa bb
    1  1 AA
    4  4 DD
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wrote a function in Python: def instantiate(c): if inspect.isclass(c): return c() elif isinstance(c,
i wrote a simple function in controller public string LinkProjectSquareFilter(int squareId) { return squareId.ToString();
I write this function, but what's its return value. (defn read-data [file] (let [code
I occasionally need to extract specific rows from a data.frame based on values from
i am trying to write one function which return sql statement like function get_sql($name=0,$date_start=0,$date_end=0)
In C++, on Linux, how can I write a function to return a temporary
How can I write a function which will return pi (π) to a given
I'm trying to write a branchless function to return the MAX or MIN of
I'm trying to write a function that will return all the available cars for
I am trying to write a JavaScript function that will return its first argument(function)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.