Skip to content
Prev 1776 / 398506 Next

Names of data frame columns in an apply

Hedderik van Rijn <rijn at swi.psy.uva.nl> writes:
You cannot use $ because the argument to recode is not a list, it is a
(non-generic) vector. Cf.
a b 
1 3 
a b 
2 4 
  1 2
a 1 2
b 3 4
1         2 
"numeric" "numeric" 


However, dataline["var1"] should work. But are you sure this is the
way to go? How about something like:

transform(dframe, type=ifelse(var1==1,1,ifelse(var2==2,2,0)))