x <- data.frame(Level=c(6.5))
x_poly <- poly(x$Level, 4, raw=TRUE)
x1 <- cbind(x, x_poly[, 2:4])
This is my code and whenever I was using cbind for some reason it was printing 3 rows and column even though both x and x_poly have only 1 row.
x_poly <- as.data.frame(x_poly[, 2:4])
print(dim(x_poly))
I tried to print the dimensions of x_poly and x_poly[,2:4]. For some reason x_poly shows 1 row on;y but x_poly[2:4] shows 3 rows.
When extracting using
`[`
, R usesdrop
(see?drop
), to coerce to the lowest possible dimensions.So from the matrix,
you will get a vector.
We can do
drop=FALSE
.Thus, what you're looking for is
Data: