I want to exclude every row from database where gender!="M" and gender!="F" and clean the database.
Thanks, in advance.
This is what I have tried:
CleanGender<-which(data$Gender!="M" & data$Gender!="F")
I want to exclude every row from database where gender!="M" and gender!="F" and clean the database.
Thanks, in advance.
This is what I have tried:
CleanGender<-which(data$Gender!="M" & data$Gender!="F")
We can use %in%
to subset multiple values on a column. It would check whether these values are present in the column, create a logical expression and subset those rows
subset(data, gender %in% c("M", "F"))
Supposing gender can't be both 'M' and 'F' (which
look sequentially at vector rows) :
# find index you want to keep
CleanGender_index <- which(data$Gender!="M" | data$Gender!="F")
# select corresponding rows, renaming your data frame is called `df_raw`
df_clean <- df_raw[CleanGender_index, ]
data
may not the best name for your dataset since it is also an R function.