[R] creating a dynamic output vector
Steve Powers
smpowers at wisc.edu
Wed Nov 7 23:27:24 CET 2007
Let's say I have a program that returns variables whose names may be any
string within the vector
NAMES=c("varA","varB","varC","varD","varE","varF"..."varZ"), but I do
not ever know which ones have actually been created. So in one example
output, "varA", "varC", and "varD" could exist, but in another example
output "varA", "varD", "varE",and "varF" exist, with no pattern or
predictability (different combinations can come out, as well as
different numbers of variables).
How do assign the output values, in pre-arranged order, into an output
vector? The output vector for the first example would be OUTPUTS=c(varA,
NA, varC, varD...) and the output vector for the second example would be
OUTPUTS=c(varA, NA, NA, varD, varE, varF...). In other words, the rows
for all potential returned values need to be retained in the order set
by NAMES, and the values all need to be plugged into their respective
spot in that order if they exist. Otherwise NA is plugged in.
One other factor is that some outputs are values, but others are text. Tips?
Using R version 2.4 on Windows XP
More information about the R-help
mailing list