简体   繁体   English

如何将数据框的一部分转换为两个箱形图以进行比较?

[英]How do I turn parts of a data frame into two box plots for comparison?

I'm trying to compare initial treatment values to initial control values from my data set. 我正在尝试将初始治疗值与数据集中的初始控制值进行比较。 My error is "subscript out of bounds". 我的错误是“下标超出范围”。 Help! 救命!

initial<- c(11.4,9.6,10.1,8.5,10.3,10.6,11.8,9.8,10.9,10.3,10.2,11.4,9.2,10.6,10.8,8.2,9.1,8.7,9.7,10.8,10.9,10.6,10.1,12.3,8.8,10.4,10.9,10.4,11.6,10.9)


final<-c(138.3,104.0,96.4,89.0,88.0,103.8,147.3,97.1,172.6,146.3,99.0,122.3,103.0,117.8,121.5,93.0,9.3,8.8,8.8,10.1,9.6,8.6,10.4,12.4,9.3,9.5,8.4,8.7,12.5,9.1)

group<-rep(c(treatment,control), times=c(16,14))
group

selenium_data<-data.frame(initial,final,group)
selenium_data

boxplot(initial[["treatment"]]~initial[["control"]])

Looks like you're off to a great start. 看来您的开端很好。 A couple small syntax things; 一些小的语法问题; I think this is performing the way you'd like. 我认为这正在执行您想要的方式。

initial<- c(11.4,9.6,10.1,8.5,10.3,10.6,11.8,9.8,10.9,10.3,10.2,11.4,9.2,10.6,10.8,8.2,9.1,8.7,9.7,10.8,10.9,10.6,10.1,12.3,8.8,10.4,10.9,10.4,11.6,10.9)

final<-c(138.3,104.0,96.4,89.0,88.0,103.8,147.3,97.1,172.6,146.3,99.0,122.3,103.0,117.8,121.5,93.0,9.3,8.8,8.8,10.1,9.6,8.6,10.4,12.4,9.3,9.5,8.4,8.7,12.5,9.1)

group<-rep(c("treatment","control"), times=c(16,14)) 
group

selenium_data<-data.frame(initial,final,group) 
selenium_data

boxplot(formula=initial~group, data=selenium_data)

箱线图示例

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM