[R] iterative read - write

Neotropical bat risk assessments neotropic@l@b@t@ @ending from gm@il@com
Tue Apr 17 13:20:02 CEST 2018


Hi all,

I would like to set up an iterative read & write sequence to avoid 
reading and writing each file one at a time.
Hundreds of data sets to re-calculate.  The code I have works well 
individually, but would like to set up an iterative read, calculate and 
write changing the input and output file names each iteration.

I  think I have read that there is an R  feature using "Pipes" and % 
that may help but have not figured out how to do this.
What I am seeking is a way to read a list of TXT files, calculate the 
values and write the results in an iterative manner to avoid manually 
reading each file individually

Suggestions?

Tnx,
Bruce*
*

*# This works*

*#read in a data file
*

*>Corbre_2 <- read.table("E:/Acoustic Parameters/~Emballonuridae/Data by 
genus/~Corbre/Corbre_2.txt",header=T,sep="\t",quote="")*

*# create and calculate a new variable for time between call pusles
*

*Corbre_2 [c("TBC")] <- recode.variables(Corbre_2[c("TBC")] , "0 -> NA;")*

*# Create new BW variable for band width then change data file name*

*BW<-within(Corbre_2,BW<-Fmax-Fmin)*

*# Create 2 new variables for fundamental H1 and third harmonic H3 
frequencies
*

*#based on Fc that is generally loudest at the 2^nd harmonic.*

*BW<-within(BW,FcH1<-Fc*.5)*

*BW<-within(BW,FcH3<-FcH1*3)*

*#rename to a DF to calculate the stats
*

*BatStats<-BW*

*BatStats<-Deducer::descriptive.table (vars = d 
(Dur,TBC,Fmin,Fmax,BW,Fmean,Fk,FcH1,Fc,FcH3,Sc,Pmc),data= 
BatStats,func.names =c("Valid N","Minimum","Maximum","Mean","St. 
Deviation"),func.additional= list(p10=function(x) quantile(x, c(0.10), 
na.rm=TRUE),p25=function(x) quantile(x, c(0.25), 
na.rm=TRUE),p75=function(x) quantile(x, 
c(0.75),na.rm=TRUE),p90=function(x) quantile(x, c(0.90),na.rm=TRUE)))*

*## Write the results and change output name and directory for the 
calculated stats.*

*write.csv(BatStats,file="C:\\=Bat data working\\Acoustic 
Parameters\\Corbre_Stats.csv")*



-- 
Bruce W. Miller, PhD.
Neotropical bat risk assessments
Conservation Fellow - Wildlife Conservation Society

If we lose the bats, we may lose much of the tropical vegetation and the lungs of the planet

Using acoustic sampling to identify and map species distributions for >25 years.

Providing free Interactive identification keys and call fact sheets for the vocal signatures of New World Bats


	[[alternative HTML version deleted]]




More information about the R-help mailing list