I have a data set that begins like this:
> d.weight
R N P C D.weight
1 1 0 0 GO 45.3
2 2 0 0 GO 34.0
3 3 0 0 GO 19.
R determines whether it should treat variables as categorical (ANOVA-type analysis) or continuous (regression-type analysis) by checking whether they are numeric
or factor
variables. Most simply, you can convert your predictor (independent) variables to factors via
facs <- c("R","N","P")
d.weight[facs] <- lapply(d.weight[facs],factor)
If you want to create auxiliary variables instead of overwriting you could do something like
for (varname in facs) {
d.weight[[paste0("f",varname)]] <- factor(d.weight[[varname]])
}
There might be a more compact way to do it but that should serve ...