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?