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.
X<-split(df, df$gender)
from this question
Split data.frame based on levels of a factor into new data.frames
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With