我是R studio的新手,在第2年学习数学模块。 我已经设置了一个问题"运行命令显示参赛者为男性的所有行#34;。我尝试过使用子集函数和$,但我似乎无法弄明白。
Age = c(25, 23, 33, 28, 35, 31, 25, 29)
Gender = c(Male, Male, Female, Female, Male, Female, Female, Female)
Cinema = c(T, T, T, T, F, F, T, F)
Shopping = c(F, F, F, T, T, T, F, F)
df = data.frame(Age, Gender, Cinema, Shopping) #data frame of dating show data
这是日期框架,有人能指出我正确的方向吗?
答案 0 :(得分:0)
首先,您需要将Gender设置为引号,以便将其识别为字符串而不是变量:
Age = c(25, 23, 33, 28, 35, 31, 25, 29)
Gender = c("Male", "Male", "Female", "Female", "Male", "Female", "Female", "Female")
Cinema = c(T, T, T, T, F, F, T, F)
Shopping = c(F, F, F, T, T, T, F, F)
df = data.frame(Age, Gender, Cinema, Shopping) #data frame of dating show data
要查看Gender = Male的所有行,您可以使用以下命令
> df[df$Gender == 'Male',]
Age Gender Cinema Shopping
1 25 Male TRUE FALSE
2 23 Male TRUE FALSE
5 35 Male FALSE TRUE