I have problems with a script that uses cbind to add columns to a data frame. I select these columns with a regex, and I like that cbind automatically provides a prefix if you add more than one column. Bit this doesn't work if you just add one column ... Even if I create this column as a data frame ...
Is there any way around this behavior?
In my example, it works fine for columns starting with column a, but not for b1.
df <- data.frame(a1=c(1,2,3),a2=c(3,4,5),b1=c(6,7,8)) cbind(df, log=log(df[grep('^a', names(df))])) cbind(df, log=log(df[grep('^b', names(df))])) cbind(df, log=as.data.frame(log(df[grep('^b', names(df))])))
r
drmariod
source share