Put them in a data frame and use the formula interface to boxplot:
x <- data.frame(a=1:10, c=rep(c('Y','N'), 5))
boxplot(a ~ c, data=x)
Question
So I think I have two vectors. The first one looks like this -
70 71 72 73 74 75 76 77
2.997500 2.680833 3.000833 5.443333 2.652500 7.115833 5.109167 5.730000
78 79 80 81 82 83 84 85
6.866667 4.562500 4.725000 2.747500 3.861667 4.980833 3.940833 4.792500
86 87 88 89 90
6.679167 3.100833 2.915833 3.904167 4.465833
[1] "double"
Where the last double comes from when I do a print typeof of the variable that holds the vector(I guess it must be a vector of doubles).
I also use this function -
findLastRowVal = function(x){
(tail(x[!is.na(x)],1))
}
with the apply function to find the last value of a bunch of rows in a data frame - these are the values -
[1] "N" "Y" "Y" "Y" "Y" "N" "Y" "N" "Y" "N" "Y" "Y" "Y" "Y" "Y" "Y" "Y" "N" "Y"
[20] "Y" "Y"
I want a box plot in which I have two diagrams - one for the Ys and one for the Ns. If there is a Y in the corresponding index in the second vector, then said value in the first vector should be plotted in the box diagram for Y.
For example, 2.99750 corresponds with N and should be a part of the box diagram for N.
How do I achieve this?
So I attempted this now -
x <- data.frame(a=1:10, c=rep(c('Y','N'), 5))
jpeg("myplot.jpg")
boxplot(a ~ c, data=x)
dev.off()
but this gives me this error -
null device
1
I assume this is because there is no myplot.jpg (which is strange to me - why isn't R just creating one?) Where should I be creating this myplot.jpg?
La solution
Put them in a data frame and use the formula interface to boxplot:
x <- data.frame(a=1:10, c=rep(c('Y','N'), 5))
boxplot(a ~ c, data=x)