[R] From FAQ 7.21 to a command like apply(sapply(list(f1,f2,f3),is.na),2,sum)

From: Heinz Tuechler <tuechler_at_gmx.at>
Date: Wed 30 Mar 2005 - 08:40:12 EST

Dear all,

Last December there was a thread regarding the famous FAQ 7.21 "How can I turn a string into a variable?" and asking what people want to do with these strings.
My, certainly trivial application would be as follows: Assume I have a data.frame containing besides others also the columns f1, f2, ..., fn and I want to create a command like: apply(sapply(list(f1,f2,f3),is.na),2,sum) or

Can I start from paste('f',1:3,sep='') to arrive at the abovementioned command?
I tried get, parse, as.name, eval in diverse combinations but did not reach a solution.
More generally my question is, how can I produce a "list" of variables like x1 to xn in a convenient way within a command. I am quite sure that this has been answered several times, but I did not find one of these answers. So I welcome any hint, where to look.

Heinz Tüchler

R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Wed Mar 30 09:46:44 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:30:57 EST