I'm trying to make a data frame to then create a boxplot from. The data frame should contain 3 vectors of varying sizes. Let's say the data is currently in a$data, b$data and c$data, and are of lengths 7, 50, 200.
a$data
b$data
c$data
Here is a simplified version of my code, where the cbind step errors:
cbind
# create initial df df <- data.frame() # set column names colnames(df) <- c("a", "b", "c") # bind original data to new data frame: df <- cbind(df, a$data, b$data, c$data) # draw boxplot boxplot(df)
A data.frame can not "contain [...] vectors of varying sizes". But lists can, e.g.
data.frame
l = list(x = rnorm(5, 2), y = rnorm(10, 3), z = rnorm(20, 1)).
l = list(x = rnorm(5, 2), y = rnorm(10, 3), z = rnorm(20, 1))
And boxplot happily eats lists:
boxplot
boxplot(l)
2.1m questions
2.1m answers
60 comments
57.0k users