Try the following code. It is basic but effective; *setwd("/home/user2/Documents")*
*Test_matrix=read.csv("Trial.csv",header=T) # The 1st table that you have considered * *Test_matrix=as.matrix(Test_matrix)* *Writer=function(mat){u=unique(mat[,"Subject"])* *l=length(u)* *dummy=lapply(1:l,FUN=function(x){string=u[x]* *step1=unlist(strsplit(string,""))* *file_name=substring(string,(which(step1=="[")+1),(which(step1=="]")-1))* *m=mat[which(mat[,"Subject"]==string),]* *dummy_matrix=matrix(rep(0,11*11),nrow=11)* *colnames(dummy_matrix)=#Names of all the 11 ppl.* *rownames(dummy_matrix)=#Names of all the 11 ppl.* *for(i in 1:11)* *{for(j in 1:11)* * {index=which(m[,"Receiver"]==rownames(dummy)[i]&m[,"Sender"]==colnames(dummy)[j]) * *count=length(index)* *dummy_matrix[i,j]=count}}* * write.csv(dummy_matrix,paste('/home/hduser/',file_name,'_counts','.csv',sep='')) * *write.csv(m,paste('/home/hduser/',file_name,".csv",sep=""))* *})}* *I hope this helps,* *Best,* *Heramb * On Tue, Sep 25, 2012 at 12:29 PM, PIKAL Petr <petr.pi...@precheza.cz> wrote: > Hi > > your data are difficult to read so I make my own > > set.seed(111) > sender<-sample(letters[1:5], 20, replace=T) > receiver<-sample(letters[1:5], 20, replace=T) > xtabs(~sender+receiver) > receiver > sender a b c d e > a 1 1 3 1 0 > b 0 1 0 1 1 > c 1 3 2 2 0 > d 0 1 0 0 1 > e 0 0 0 1 0 > > If you want such result from each subject of your table }presumably > data.frame just split and lapply it > > untested > lapply(split(your.data, by a column), function (x) > xtabs(~x$sender+x$receiver)) > > Regards > > Petr > > > > -----Original Message----- > > From: r-help-boun...@r-project.org [mailto:r-help-bounces@r- > > project.org] On Behalf Of s.s.m. fauzi > > Sent: Tuesday, September 25, 2012 4:06 AM > > To: r-help@r-project.org > > Subject: [R] mapping data from table to .csv template > > > > I have a .csv table named mailing.csv as below. It consist a receiver, > > subject and sender. > > > > Receiver subject sender > > 1 Adrian Cole RE: [WHIRR-117] Composable services Tom White > > 2 Adrian Cole RE: [WHIRR-117] Composable services Tom White > > 3 Adrian Cole RE: [WHIRR-117] Composable services Adrian Cole > > 4 Adrian Cole RE: [WHIRR-117] Composable services Adrian Cole > > 5 Adrian Cole RE: [WHIRR-117] Composable services Tom White > > 6 Adrian Cole RE: [WHIRR-117] Composable services Adrian Cole > > 7 Adrian Cole RE: [WHIRR-117] Composable services Tom White > > 8 Adrian Cole RE: [WHIRR-117] Composable services Tom White > > 9 Adrian Cole RE: [WHIRR-117] Composable services Adrian Cole > > 10 Adrian Cole RE: [WHIRR-117] Composable services Adrian Cole > > 11 Adrian Cole RE: [WHIRR-117] Composable services Tom White > > 12 Adrian Cole RE: [WHIRR-117] Composable services Tom White > > 13 Adrian Cole RE: [WHIRR-117] Composable services Tom White > > 14 Adrian Cole RE: [WHIRR-117] Composable services Tom White > > 15 Patrick Hunt RE: [WHIRR-123] Cassandra integration Tom White > > 16 Patrick Hunt RE: [WHIRR-123] Cassandra integration Andrei Savu > > 17 Patrick Hunt RE: [WHIRR-123] Cassandra integration Andrei Savu > > 18 Patrick Hunt RE: [WHIRR-123] Cassandra integration Tom White > > 19 Patrick Hunt RE: [WHIRR-123] Cassandra integration Tom White > > 20 Patrick Hunt RE: [WHIRR-123] Cassandra integration Adrian Cole > > 21 Patrick Hunt RE: [WHIRR-123] Cassandra integration Tom White22 > > Patrick Hunt RE: [WHIRR-123] Cassandra integration Patrick Hunt > > > > What I would like to do is to update/map the information from table > > above to .csv template (namedAC_template.csv), and save it in a > > separate file using subject details in backet as file name (for > > instance AC_WHIRR-117). As for table above, it should create two new > > files name as AC_WHIRR-117and AC_WHIRR-123. > > > > sample .csv template (AC_template.csv) is as below: > > > > Adrian.Cole Patrick.Hunt Andrei.Savu Bruno.Dumon > > Edward.J..Yoon Eugene.Koontz Jakob.Homan Kelvin.Kakugawa Tom.White > > Adrian Cole 0 0 0 0 > > 0 0 0 0 0 > > Patrick Hunt 0 0 0 0 > > 0 0 0 0 0 > > Andrei Savu 0 0 0 0 > > 0 0 0 0 0 > > Bruno Dumon 0 0 0 0 > > 0 0 0 0 0 > > Edward J. Yoon 0 0 0 0 > > 0 0 0 0 0 > > Eugene Koontz 0 0 0 0 > > 0 0 0 0 0 > > Jakob Homan 0 0 0 0 > > 0 0 0 0 0 > > Kelvin Kakugawa 0 0 0 0 > > 0 0 0 0 0 > > Tom White 0 0 0 0 > > 0 0 0 0 0 > > Lars George 0 0 0 0 > > 0 0 0 0 0 > > Soren Macbeth 0 0 0 0 > > 0 0 0 0 0 > > Lars.George Soren.Macbeth > > Adrian Cole 0 0 > > Patrick Hunt 0 0 > > Andrei Savu 0 0 > > Bruno Dumon 0 0 > > Edward J. Yoon 0 0 > > Eugene Koontz 0 0 > > Jakob Homan 0 0 > > Kelvin Kakugawa 0 0 > > Tom White 0 0 > > Lars George 0 0 > > Soren Macbeth 0 0 > > > > Sample output for this question is as below: > > > > sample output for AC_WHIRR-117: > > > > Adrian.Cole Patrick.Hunt Andrei.Savu Bruno.Dumon > > Edward.J..Yoon Eugene.Koontz Jakob.Homan Kelvin.Kakugawa Tom.White > > Adrian Cole 0 0 0 0 > > 0 0 0 0 9 > > Patrick Hunt 0 0 0 0 > > 0 0 0 0 0 > > Andrei Savu 0 0 0 0 > > 0 0 0 0 0 > > Bruno Dumon 0 0 0 0 > > 0 0 0 0 0 > > Edward J. Yoon 0 0 0 0 > > 0 0 0 0 0 > > Eugene Koontz 0 0 0 0 > > 0 0 0 0 0 > > Jakob Homan 0 0 0 0 > > 0 0 0 0 0 > > Kelvin Kakugawa 0 0 0 0 > > 0 0 0 0 0 > > Tom White 9 0 0 0 > > 0 0 0 0 0 > > Lars George 0 0 0 0 > > 0 0 0 0 0 > > Soren Macbeth 0 0 0 0 > > 0 0 0 0 0 > > Lars.George Soren.Macbeth > > Adrian Cole 0 0 > > Patrick Hunt 0 0 > > Andrei Savu 0 0 > > Bruno Dumon 0 0 > > Edward J. Yoon 0 0 > > Eugene Koontz 0 0 > > Jakob Homan 0 0 > > Kelvin Kakugawa 0 0 > > Tom White 0 0 > > Lars George 0 0 > > Soren Macbeth 0 0 > > > > Sample output for AC_WHIRR-123 > > > > Adrian.Cole Patrick.Hunt Andrei.Savu Bruno.Dumon > > Edward.J..Yoon Eugene.Koontz Jakob.Homan Kelvin.Kakugawa Tom.White > > Adrian Cole 0 1 0 0 > > 0 0 0 0 0 > > Patrick Hunt 1 0 2 0 > > 0 0 0 0 4 > > Andrei Savu 0 2 0 0 > > 0 0 0 0 0 > > Bruno Dumon 0 0 0 0 > > 0 0 0 0 0 > > Edward J. Yoon 0 0 0 0 > > 0 0 0 0 0 > > Eugene Koontz 0 0 0 0 > > 0 0 0 0 0 > > Jakob Homan 0 0 0 0 > > 0 0 0 0 0 > > Kelvin Kakugawa 0 0 0 0 > > 0 0 0 0 0 > > Tom White 0 4 0 0 > > 0 0 0 0 0 > > Lars George 0 0 0 0 > > 0 0 0 0 0 > > Soren Macbeth 0 0 0 0 > > 0 0 0 0 0 > > Lars.George Soren.Macbeth > > Adrian Cole 0 0 > > Patrick Hunt 0 0 > > Andrei Savu 0 0 > > Bruno Dumon 0 0 > > Edward J. Yoon 0 0 > > Eugene Koontz 0 0 > > Jakob Homan 0 0 > > Kelvin Kakugawa 0 0 > > Tom White 0 0 > > Lars George 0 0 > > Soren Macbeth 0 0 > > > > Appreciate help from the expert... > > > > [[alternative HTML version deleted]] > > > > ______________________________________________ > > R-help@r-project.org mailing list > > https://stat.ethz.ch/mailman/listinfo/r-help > > PLEASE do read the posting guide http://www.R-project.org/posting- > > guide.html > > and provide commented, minimal, self-contained, reproducible code. > > ______________________________________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide > http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > [[alternative HTML version deleted]] ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.