Hi,
Use ?reshape()
dat1<- read.table(text="V1 V2       V3     V4 V5
1 210505  ARS    B  A
1 210505  BFGL   A  B
1 210505  NGS    B  B
1 210506 ARS     B  B
1 210506 BFGL    A  A
1 210506 NGS     B  B
1 210507  ARS    B  B
1 210507 BFGL    A  B
1 210507 NGS     A  B",sep="",header=TRUE,stringsAsFactors=FALSE) 


 res <- reshape(dat1[,-1],timevar="V2",idvar="V3",direction="wide")
colnames(res)[-1] <-gsub(".*\\.","",colnames(res)[-1])
 res
#    V3 210505 210505 210506 210506 210507 210507
#1  ARS      B      A      B      B      B      B
#2 BFGL      A      B      A      A      A      B
#3  NGS      B      B      B      B      A      B


A.K.


Dear R users I have a question. 

I have example file: 

V1 V2       V3     V4 V5 
1 210505  ARS    B  A 
1 210505  BFGL   A  B 
1 210505  NGS    B  B 
1 210506 ARS     B  B 
1 210506 BFGL    A  A 
1 210506 NGS     B  B 
1 210507  ARS    B  B 
1 210507 BFGL    A  B 
1 210507 NGS     A  B 

from which I want to get file which looks like this: 

V2      210505 210505   210506  210506  210507 210507 
ARS      B            A          B           B          B            B 
BFGL    A             B          A          A          A             B 
NGS     B             B          B          B          A             B 


I think this can be done with a loop but unfortunatelly I'm not experienced 
with loops. 
Thank you very much for help!

______________________________________________
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.

Reply via email to