Reputation: 29
I have the following data
structure(list(one = c(15L, 9L, 4L, 34L, 17L, 18L, 14L, 12L,
13L, 26L, 31L), two = c(31L, 35L, 29L, 28L, 12L, 18L, 30L, 14L,
22L, 10L, 29L)), .Names = c("one", "two"), class = "data.frame", row.names = c(NA,
-11L))
I need to first create a third variable which has the first 6 rows "A" and the other rows"B". I then need to create a boxplot between "one" and this variable. I tried doing
boxplot(category ~ one, mydata3, v= TRUE,main="boxplotrelationship")
but it won't work. Any help?
Upvotes: 1
Views: 523
Reputation: 2177
I think I just answered part of your question in a similar question you asked, but here goes!
You have a couple problems here: first, your structure isn't assigned to any variable, so you can't reference it later in a boxplot. Below, see how I've assigned it to mydata3
first.
Also, since category
is your grouping variable, it's not category ~ one
, but the reverse -- one ~ category
.
mydata3 <- structure(list(one = c(15L, 9L, 4L, 34L, 17L, 18L, 14L, 12L,
13L, 26L, 31L), two = c(31L, 35L, 29L, 28L, 12L, 18L, 30L, 14L,
22L, 10L, 29L)), .Names = c("one", "two"), class = "data.frame", row.names = c(NA,
-11L))
mydata3[1:6,'category'] <- 'A'
mydata3[7:11, 'category'] <- 'B'
boxplot(one ~ category, mydata3,v=TRUE,main="boxplotrelationship")
Upvotes: 1