I have a data frame in R where one of the columns is gender
. The values of gender
are factors with "f" or "m" though if the data set is bad, it could be more (for instance NA).
I'm trying to split the data frame into a list of data frames with gender being unique. This way I can run the same models on the different populations.
Is there a better way then basically:
dfMale <- mydata[which(mydata$gender == "m"),]
dfFemale <- mdata[which(mydata$gender == "f"),]
dfOther <- mydata[!(1:dim(mydata][1] %in% c(which(mydata$gender == "m"),which(mydata$gender == "f"))]
Thanks.