Running R 1.1 on RedHat Linux 6.2.
I need to write a shell script that goes through a bunch of directories
of simulation output, creating summary files that have the mean and
standard deviation of the variables found in the data files in each
directory. I've got the R code doing almost the right thing. It reads
in data, then gets the mean and standard deviation for the numeric
variables, puts those results together, and then grabs the directory
name from the system and jams that in to the results as well. Here is
what I have:
data<-read.table("lastline.txt",header=T,as.is = TRUE)
indices<-1:dim(data)[2]
indices<-na.omit(ifelse(indices*sapply(data,is.numeric),indices,NA))
mean<-sapply(data[,indices],mean)
sd<-sapply(data[,indices],sd)
dir<-system("pwd",TRUE)
newOutput<-rbind(mean,sd)
transNewOutput<-t(newOutput)
transNewOutput<-rbind(dir,transNewOutput)
write.table(transNewOutput,file="Atestoutput",quote=FALSE,
sep="\t")
The output file looks like this:
mean sd
dir /home/pauljohn/swarm/src /home/pauljohn/swarm/src
T 732.1 148.618520536522
Run 49.5 29.011491975882
Seed 499366074.13 296739559.579976
IntAct 43.85 5.592879672432
Change 0 0
Now the questions:
1. I want 3 columns of output, but here the first line only has two
items. I can't see any way to make it put out a lable for the first
column, like "Variable" or some such.
2. Can you tell me how to truncate the numerical printout so it only
shows two numbers after the decimal point?
3. Is my way of keeping track of the directory completely ridiculous?
How else would you do it?
4. My next chore is to find how to make this thing run through a series
of directories, summarizing each. Would you recommend I do this with a
shell script or something within R itself?
--
Paul E. Johnson email: pauljohn at ukans.edu
Dept. of Political Science http://lark.cc.ukans.edu/~pauljohn
University of Kansas Office: (785) 864-9086
Lawrence, Kansas 66045 FAX: (785) 864-5700
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at
stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Paul Johnson
2000-Aug-07 19:11 UTC
[R] Thanks for all the help (re: Trying to "pretty up" output from R job
Paul E Johnson wrote:> > Running R 1.1 on RedHat Linux 6.2.This is about the best email list I've ever been in. Unceasingly helpful and polite. I got quick answers from 10 different people telling me 5 different ways to round numbers after two decimal places and several other ways to fiddle the output format. Awesome. Just for the record, my opinion is that, if you need to have an R thing done in each subdirectory, and each subdirectory's name can be some completely arbitrary thing that you can't predict ahead of time, it is much easier to make a shell script that traverses the directory structure than it is to write an R program that goes into the subdirectories. The shell script just needs: #!/bin/sh for file in *; do echo $file if [ -d $file ] then cd $file R BATCH ../Rcollector.R cd .. fi done -- Paul E. Johnson email: pauljohn at ukans.edu Dept. of Political Science http://lark.cc.ukans.edu/~pauljohn University of Kansas Office: (785) 864-9086 Lawrence, Kansas 66045 FAX: (785) 864-5700 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._