How to add a new variable to an existing data frame, but I want to add to the front not end. eg. my dataframe is
b c d 1 2 3 1 2 3 1 2 3
I
Use cbind e.g.
cbind
df <- data.frame(b = runif(6), c = rnorm(6)) cbind(a = 0, df)
giving:
> cbind(a = 0, df) a b c 1 0 0.5437436 -0.1374967 2 0 0.5634469 -1.0777253 3 0 0.9018029 -0.8749269 4 0 0.1649184 -0.4720979 5 0 0.6992595 0.6219001 6 0 0.6907937 -1.7416569