我有以下df:
Subject Condition Score
John Hard 1
John Easy 1
Simon Hard 2
Simon Easy 3
Mary Hard 1
Mary Hard 2
Kevin Hard 2
Kevin Easy 3
我想将此df的子集仅包含来自已完成“条件”因子的两个级别(即,简单和硬)的主题的数据。生成的df应如下所示:
Subject Condition Score
John Hard 1
John Easy 1
Simon Hard 2
Simon Easy 3
Kevin Hard 2
Kevin Easy 3
我尝试了以下内容:
dfNew <- subset(df, Condition==c("Easy", "Hard"), select=Subject)
dfNew2 <- subset(with(df, Subject, Condition == "Easy" & Condition == "Hard"))
但是我收到了错误和警告信息。
非常感谢任何帮助。