I'm trying to remove rows from a dataframe if they satisfy an if/and statement (although I don't necessarily need to use the if& statement). So if the column "activity" has an "NA" in the cell AND if the column "speed" has the value of "f" then remove those rows. Here are some of the things I've tried so far:
Attempt 1:
data<-data[!((data$activity != "NA") && (data$speed == "f")),]
Attempt 2:
for (i in 1:nrow(data)) {
if(data$activity != "NA" && data$speed == "f")
{data[i,"Keep"]<-c("no")}
}
rm(data$Keep == "no")
Attempt 3:
if(surveysdb$activity != "NA" && surveysdb$predominant_activity == "f")
{rm (#not sure what to put here)}
Thank you in advance!
Aucun commentaire:
Enregistrer un commentaire