[R] calling data frames
Rogério Rosa da Silva
rrsilva at ib.usp.br
Tue May 11 14:30:15 CEST 2004
Dear List,
I've around 1000 *.txt files, I've generate with other software.
I've now done the following code (below).
My question is how can I automate this (with do.call () ?), so it could be
done for all the *.txt files.
Thanks in advance,
Rogério
names<- list.files()
file <- "BLU_Var_%04d.txt"
for(i in 1:1000){
blumenau<-read.table("Blu_1.txt",h=T) # 1000 *.txt files
Guildas<-data.frame(cbind(t(blumenau[2:50])))
Guilda1<-cbind(X27,X48)
Guilda2<-cbind(X5,X17,X19,X20,X21,X24,X25,X26,X40,X41,X77)
Guilda3<-cbind(X22,X28,X69)
Guilda4<-cbind(X29,X30,X31,X32,X33,X34,X35,X36,X37,X78)
Guilda5<-cbind(X3,X8,X18,X23,X63,X82,X83)
Guilda6<-cbind(X6,X38,X39,X44,X45,X46,X47,X49,X50,X51,X52,X53,X54,X55,X56,X57,X58,X59,X60,X61,X62,X84)
Guilda7<-cbind(X1,X2,X42,X43,X64,X65,X66,X67,X68,X79,X80)
Guilda8<-cbind(X7,X15,X16,X70,X71,X72,X73,X74,X75,X76)
Guilda9<-cbind(X4,X9,X10,X11,X12,X13,X14,X81)
Resul.Guilda1<-sum(apply(Guilda1,2,sum))
Resul.Guilda2<-sum(apply(Guilda2,2,sum))
Resul.Guilda3<-sum(apply(Guilda3,2,sum))
Resul.Guilda4<-sum(apply(Guilda4,2,sum))
Resul.Guilda5<-sum(apply(Guilda5,2,sum))
Resul.Guilda6<-sum(apply(Guilda6,2,sum))
Resul.Guilda7<-sum(apply(Guilda7,2,sum))
Resul.Guilda8<-sum(apply(Guilda8,2,sum))
Resul.Guilda9<-sum(apply(Guilda9,2,sum))
Guild.Richness<-cbind(Resul.Guilda1,Resul.Guilda2,Resul.Guilda3,Resul.Guilda4,Resul.Guilda5,Resul.Guilda6,Resul.Guilda7,Resul.Guilda8,Resul.Guilda9)
write(Guild.Richness, file = sprintf(file, i), ncol = 9)
}
--
Rogério R. Silva
MZUSP http://www.mz.usp.br
Linux User #354364
Linux counter http://counter.li.org
More information about the R-help
mailing list