0

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"]])
d.b
  • 32,245
  • 6
  • 36
  • 77

1 Answers1

0

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)

boxplot example

Michael Roswell
  • 1,300
  • 12
  • 31
  • I think that the error you ran into was because of the double square brackets you used/ the way you were referring to your data. This post might help with that: [https://stackoverflow.com/questions/1169456/the-difference-between-bracket-and-double-bracket-for-accessing-the-elem](https://stackoverflow.com/questions/1169456/the-difference-between-bracket-and-double-bracket-for-accessing-the-elem) – Michael Roswell Feb 10 '19 at 03:36
  • Oh my goodness! You're a genius! Thank you so much! I've not used 'formula' and 'data'. Why did that do the trick? – Mary Feb 10 '19 at 03:37
  • Got it! Thanks again. – Mary Feb 10 '19 at 03:41
  • Try `?boxplot`. In a lot of R functions one way of specifying the relationships between variables is with that formula type thing with the tilde, where unquoted variable names refer to columns in whatever the data argument is. – Michael Roswell Feb 10 '19 at 03:41