Hello, does anyone know how to add a new column to a data frame?
DF <- data.frame (predictor=c ("a", "a", "b", "b"), respuesta=c (13.5, 0, 2.6, 4.1))
Hello, does anyone know how to add a new column to a data frame?
DF <- data.frame (predictor=c ("a", "a", "b", "b"), respuesta=c (13.5, 0, 2.6, 4.1))
There are several ways to add new columns. Some of them are:
Add them when creating the data.frame
:
DF <- data.frame (predictor=c ("a", "a", "b", "b"), respuesta=c (13.5, 0, 2.6, 4.1),
ColNueva=rnorm(4))
If the object is already created:
DF[,3] <- rnorm(4)
DF$ColNueva<- rnorm(4)
DF<- data.frame(DF, ColNueva=rnorm(4))
cbind(DF, ColNueva=rnorm(4))
For a future question, you should specify which output you would like.