[R] Creating new dataset based on variable name
Scott
ncbi2r at googlemail.com
Thu Aug 25 23:35:05 CEST 2011
>for (i in 1:NROW(vector.with.names)
You need length instead of nrow (lowercase) which will be NULL for a vector.
>I also want to convert the name from file name to something I can
understand
For this part of your statement,
I think you're after the assign function (included in basic install of R) to
go from a string to an object of that name
?assign
assign(objectname,values_to_be_assigned_to_object)
a<-"doctor2008visit"
assign(a,c(7,5,4))
print(doctor2008visit)
The opposite of assign() is
?get
Depending on what you want to do, this should help you out but if you do use
assign() please remember that the object name you work with later in the
loop will change each time so you'll need to use get() to copy with that. If
reading in a number of files, and processing them, I'll usually just call
the variable "input.file" or something like that.
The question mark above in my post just means to open up the help page for
the function. You can usually use help(functionname) as well.
--
View this message in context: http://r.789695.n4.nabble.com/Creating-new-dataset-based-on-variable-name-tp3769285p3769478.html
Sent from the R help mailing list archive at Nabble.com.
More information about the R-help
mailing list