Back to the Top
The following message was posted to: PharmPK
I am trying to incorporate the factors of FOR loops into the filename
that is output with simulation results. Can anyone share how to use
SPLUS or R scripting to export data to a filename constructed of say,
"SIM" followed by the values for [i],[ j], and [k], so that it would
be saved within the FOR loops as:
SIMijk.csv
Thank you very much in advance
--
Paul R. Hutson, Pharm.D.
Associate Professor
UW School of Pharmacy
777 Highland Avenue
Madison WI 53705-2222
Tel 608.263.2496
Fax 608.265.5421
Back to the Top
The following message was posted to: PharmPK
In S-Plus, within the for loop, you can do 'write.table' or 'exportData'
with a 'paste' command for your filename.
Example: exportData(simdata,paste("SIM",i,j,k,sep="")),
where simdata is the data you construct in the for loop.
The 'assign' command can be used if you would also like to create an
object
copy of simdata from the loop into the S-Plus object explorer.
Example: assign(paste("SIM",i,j,k,sep=""),simdata)
Hope this helps.
Liviawati Sutjandra
Amgen, Thousand Oaks, CA.
Back to the Top
The following message was posted to: PharmPK
Paul Hutson wrote:
> I am trying to incorporate the factors of FOR loops into the filename
> that is output with simulation results. Can anyone share how to use
> SPLUS or R scripting to export data to a filename constructed of say,
> "SIM" followed by the values for [i],[ j], and [k], so that it
would be
> saved within the FOR loops as:
>
> SIMijk.csv
Hello Paul,
This R script should be close to what you want:
i<-1
k<-2
j<-3
collected.names <- paste(i,k,j, sep="")
file.name.out <- paste("SIM",collected.names,".csv", sep="")
write.table(Theoph, file = file.name.out, sep=",", row.name=F)
"Paste" is your friend here, and Theoph of course is one of the built-in
datasets.
Regards, Richard
--
Dr Richard Upton
Principal Medical Scientist/Senior Lecturer
Department of Anesthesia and Intensive Care
Royal Adelaide Hospital/University of Adelaide
North Tce, SA 5000, Australia
richard.upton.at.adelaide.edu.au
Phone: 61-(0)8-8303-6382
FAX: 61-(0)8-8303-3909
Back to the Top
remove (ls())
location <- "C:\\trialruns\\"
for (i in 1:5)
{
mns=rnorm(1000, mean=0, sd=i*.1)
unique.file=paste(location,"SIM",i,".csv")
write.table(mns, file=unique.file, sep = ",")
}
PharmPK Discussion List Archive Index page
Copyright 1995-2010 David W. A. Bourne (david@boomer.org)