Re: [R] Column name defined by function variable

2010-06-17 Thread Ivan Calandra
Now that I take a better look at your function, I don't understand everything, but this should work (it works for me, if I understood correctly at least what you're looking for): add.col <- function(df, new.col, name) { n.row <- dim(df)[1] length(new.col) <- n.row test <- cbind(df,

Re: [R] Column name defined by function variable

2010-06-17 Thread Ralf B
Sorry, its late and I am getting tired ;) I modified based on your suggestion: #combine data add.col <- function(df, new.col, name) { n.row <- dim(df)[1] length(new.col) <- n.row names(new.col) <- name cbind(df, new.col) } data <- data.frame(stuff1=as.numeric(d2$p

Re: [R] Column name defined by function variable

2010-06-17 Thread Ivan Calandra
Hi, I haven't check much of what you wrote, so just a blind guess. What about in the function's body before cbind(): names(new.col) <- "more stuff" ? HTH, Ivan Le 6/17/2010 11:09, Ralf B a écrit : Hi all, probably a simple problem for you but I am stuck. This simple function adds columns (

[R] Column name defined by function variable

2010-06-17 Thread Ralf B
Hi all, probably a simple problem for you but I am stuck. This simple function adds columns (with differing length) to data frames: add.col <- function(df, new.col) { n.row <- dim(df)[1] length(new.col) <- n.row cbind(df, new.col) } Now I would like to extend that method