I am trying to import several different SAS transport files into R. I know how to get the files into R as data frames, however, I don't want to do this one at a time for all ~60 data sets. I also want to convert the name from file name to something I can understand (e.g., from q181 to doctor.visits.2008). I created a vector with the new names what I was was hoping to do was something like for (i in 1:NROW(vector.with.names){ paste(vector.with.names[i], sep = "") <- read.xport('file_path', xport_file_name, sep = "") } Each part will paste what I want (e.g, doctor.visits.2008) and the correct file path and name, however, I get the error that R cannot find paste<-. I also tried using noquote() but that didn't fix it, but it did create a char vector that had the code I would need to run. I have to think there is an easy way to do it but being a relative newbie to R, I can't seem to figure it out. -- View this message in context: http://r.789695.n4.nabble.com/Creating-new-dataset-based-on-variable-name-tp3769285p3769285.html Sent from the R help mailing list archive at Nabble.com.
>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 canunderstand 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.
On Aug 25, 2011, at 4:19 PM, JacobSimmering wrote:> I am trying to import several different SAS transport files into R. > I know > how to get the files into R as data frames, however, I don't want to > do this > one at a time for all ~60 data sets. I also want to convert the name > from > file name to something I can understand (e.g., from q181 to > doctor.visits.2008). > > I created a vector with the new names what I was was hoping to do was > something like > > for (i in 1:NROW(vector.with.names){ > paste(vector.with.names[i], sep = "") <- read.xport('file_path', > xport_file_name, sep = "") > }?get ?assign> > Each part will paste what I want (e.g, doctor.visits.2008) and the > correct > file path and name, however, I get the error that R cannot find > paste<-. I > also tried using noquote() but that didn't fix it, but it did create > a char > vector that had the code I would need to run. > > I have to think there is an easy way to do it but being a relative > newbie to > R, I can't seem to figure it out.-- David Winsemius, MD West Hartford, CT
Scott/David, Thanks for your help - what I was looking for was assign. This takes care of my question. -- View this message in context: http://r.789695.n4.nabble.com/Creating-new-dataset-based-on-variable-name-tp3769285p3769620.html Sent from the R help mailing list archive at Nabble.com.