In R, how to make a boxplot?

1k views Asked by At

My input table has two columns like this:

x    y
1    187
2    235
3    857
3    253
2    955
1    267

I want to make a boxplot of the y values for each individual x value. The x values are limited to 1, 2, 3.

Here is my R code:

data=read.table("input.txt")
arr=array(dim=3)
for (i in 1:3)
{
    arr[i]=data[data.x==i,"y"] // This line raises warnings.
}
boxplot(arr)

How to correct my code?

1

There are 1 answers

1
Stephan Kolassa On
foo <- data.frame(x=rep(1:5,each=20),y=rnorm(100))
with(foo,boxplot(y~x))

enter image description here