I have an original data.frame
and I would like to run lapply
on certain columns then cbind
the remaining columns with the results from the lapply
operation.
See code below. I would ideally like b
to contain the first id
column from the data.frame
with the results from the lapply
. I am assuming my error is that my list
argument to cbind
contains a list
of lists...the first argument to list
is a vector, which could be handled, but the second argument is an actual list
itself. Just wondering how to handle this.
Thanks!
df <- data.frame(id = 1:10,
colB = 11:20,
colC = 21:30)
a <- lapply(df[,2:3],
function(x) {x = 10 * x}
)
b <- do.call(cbind,
list(df[,1],
a))
Created on 2019-02-16 by the reprex package (v0.2.0).