[R] Help with declaring factors in a function
Evan Kransdorf
evan.kransdorf at gmail.com
Thu Feb 19 02:40:00 CET 2015
Hello,
I am passing a df to a function and then want to declare factors (based on
a vector of column names in the df) for a logistic regression. I am having
trouble - R doesn't seem to recognize the factors as declared in the
function? Below is my code. Does anyone have any ideas?
MyFunction <- function(x,y,z) {
#x is a data frame
#y is a formula for the regression
#z vector of factors to be declared
name<-NULL
temp<-NULL
for (i in 1 : length(z)) {
name<-paste0(substitute(x),"$",z[i])
print(name)
temp<-eval(parse(text = name))
temp<-factor(temp)
print(levels(temp))
} #for
model<-glm(y, x, family=binomial(link = "logit"))
return(model)
} #func
Thanks very much!!!
[[alternative HTML version deleted]]
More information about the R-help
mailing list