我正在使用R中的dative数据框,我试图仅针对Modality绘制LengthOfRecipient =='nonpronomial'。我收集了所有的LengthOfRecipient =='nonpronomial':
library('languageR')
lor.np = dative[dative$PronomOfRec == 'nonpronominal',]$LengthOfRecipient
我已尝试嵌套此子集函数,并应用了向量,但我无法找到一种方法,然后只访问lor.np
中的项目的模态列,并将其存储在mod.np
中,以便我可以用以下方式绘制和分析数据:
boxplot(lor.np, mod.np)
我对R很新,语法非常混乱。任何帮助将非常感激。提前谢谢!
答案 0 :(得分:0)
可能更容易一次选择所需的所有列,然后使用formula
中的boxplot
功能而不是使用向量:
library('languageR')
lor.np <- dative[dative$PronomOfRec == 'nonpronominal',
c('LengthOfRecipient','Modality')]
head(lor.np)
# LengthOfRecipient Modality
# 2 2 written
# 3 1 written
# 5 2 written
# 6 2 written
# 7 2 written
# 11 2 written
## but you don't even need to select the columns:
lor.np <- dative[dative$PronomOfRec == 'nonpronominal', ]
boxplot(LengthOfRecipient ~ Modality, lor.np)
查看数据后,您不需要droplevels
,但这是一个可能有用的示例:
dat1 <- dative[dative$Modality == 'written', ]
boxplot(LengthOfRecipient ~ Modality, dat1)