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

  • Home
  • SEARCH
  • 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 8404609
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T22:38:32+00:00 2026-06-09T22:38:32+00:00

I am having trouble referencing columns in a dataframe by name. The function i

  • 0

I am having trouble referencing columns in a dataframe by name. The function i have begins with extracting rows where no NA’s are present:

prepare <- function(dataframe, attr1,attr2){
subset_na_still_there <- dataframe[!is.na(attr1) & !is.na(attr2),]
subset_na_still_there2 <- subset(dataframe, !is.na(attr1) & !is.na(attr2))
### someother code goes here
}

However, the subsets that are returned still contain NA’s. I get no errors.
Here is a related question

edit:
Selecting the columns and then referencing them by number does the trick:

prepare <- function(dataframe, attr1,attr2){
subset_cols <- dataframe[,c(attr1, attr2)]
subset_gone <- subset_cols[!is.na(subset_cols[,1]) & !is.na(subset_cols[,2]),]
}

Why does the first version not work as expected?

  • 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-09T22:38:34+00:00Added an answer on June 9, 2026 at 10:38 pm

    How about this:

    prepare <- function(x, attr1, attr2){
      x[!is.na(x[attr1]) & !is.na(x[attr2]),]
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Having trouble with each function... Will try to explain by example... In my code,
Having Trouble with Entity Framework. I have been populating EntityReferences with an EntityKey inorder
Im having a little trouble in referencing indexes in arrays in Smarty. I believe
I am having trouble understanding this code: $.functionone = function(){ function setOptions(newOptions){ ... }
Having trouble determining if a file name conforms to a specific convention as follows.
Having trouble rewriting the name of a flash file: /flash/shell.1257347618.swf (the numbers are a
I'm having trouble referencing the proper html elements with the javascript this reference using
I am having real trouble referencing a simple image in a jar file. I
I am having some trouble wrapping my head around virtual proxies. I have read
I'm having trouble referencing one view controller from another. The code works but I

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.