I have a data frame with subset groups, gender and other things. I am trying to retrieve data of males, then I use the command
data[data$gender == "male",]
But it keeps to say incorrect number of dimensions, how to solve it?
I have a data frame with subset groups, gender and other things. I am trying to retrieve data of males, then I use the command
data[data$gender == "male",]
But it keeps to say incorrect number of dimensions, how to solve it?
An illustration using dplyr.
library(dplyr)
df <- data.frame(gender = rep(c("male", "female"), each=5),
loveToBuy = c("car", "car", "computer", "rolex", "boat",
rep("handbag", 5)))
df2 = df %>% filter(gender == "male")
df2
# gender loveToBuy
# 1 male car
# 2 male car
# 3 male computer
# 4 male rolex
# 5 male boat