我有一个包含子集,性别和其他内容的数据框。 我正在尝试检索男性的数据,然后我使用命令
data[data$gender == "male",]
但它不断说明维数不正确,如何解决?
答案 0 :(得分:1)
使用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