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,
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
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 (
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
4 matches
Mail list logo