Re: [R] passing field name parameter to function

2009-10-10 Thread David Winsemius
On Oct 10, 2009, at 9:27 PM, tdm wrote: Hi, I am passing a data frame and field name to a function. I've figured out how I can create the formula based on the passed in field name, but I'm struggling to create a vector based in that field. for example if I hard code with the actual field

Re: [R] passing field name parameter to function

2009-10-10 Thread David Winsemius
You code is not reproducible. Take a look at this much simpler example: > a x y xx xxx 1 1 4 8 12 2 2 5 9 13 3 3 6 10 14 4 4 7 11 15 5 1 4 8 12 6 2 5 9 13 7 3 6 10 14 8 4 7 11 15 > funct <- function(df, colnm) print(df[, colnm]) > funct(a, "xx") [1] 8 9 10 11 8 9 10 11 #-

Re: [R] passing field name parameter to function

2009-10-10 Thread jim holtman
You need to understand how accessing elements of a dataframe happen, especially the '[[' operator (?"[[") x <- function(dataFrame, name) dataFrame[[name]] On Sat, Oct 10, 2009 at 9:27 PM, tdm wrote: > > Hi, > > I am passing a data frame and field name to a function. I've figured out how > I can

[R] passing field name parameter to function

2009-10-10 Thread tdm
Hi, I am passing a data frame and field name to a function. I've figured out how I can create the formula based on the passed in field name, but I'm struggling to create a vector based in that field. for example if I hard code with the actual field name Y = df$Target, everything works fine.