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
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
#-
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
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.
4 matches
Mail list logo