0

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?

Josh O'Brien
  • 159,210
  • 26
  • 366
  • 455
  • Welcome to StackOverflow! It seems to me that you used the correct code. Please read the info about [how to ask a good question](http://stackoverflow.com/help/how-to-ask) and how to produce a [minimal reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example/5963610#5963610). This will make it much easier for others to help you. – Jaap Oct 14 '14 at 12:52
  • Guess you are having a data frame. Try library(dplyr); df %>% filter(gender == "male") – KFB Oct 14 '14 at 12:54
  • If this is data frame, code presented in question will work anyway. I guess the class of data is not the issue. – Adii_ Oct 14 '14 at 13:06

1 Answers1

1

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
KFB
  • 3,501
  • 3
  • 15
  • 18