Dear R Users! I'm new in R! I've got a data.frame. For example:a<-data.frame(cbind( 0:1, 1:10)) X1 X2 1 0 1 2 1 2 3 0 3 4 1 4 5 0 5 6 1 6 7 0 7 8 1 8 9 0 9 10 1 10 Firstly i want to create combinations from X2, for example:combn(a$X2,2) It's ok, butsecondly I would like to get combinations from those X2 numbers only , where X1= 0. Could you help me? Thanks! [[alternative HTML version deleted]]
On Aug 19, 2012, at 5:14 PM, Dik?n Szabolcs Andr?s wrote:> Dear R Users! I'm new in R! I've got a data.frame. For > example:a<-data.frame(cbind( 0:1, 1:10)) X1 X2 > 1 0 1 > 2 1 2 > 3 0 3 > 4 1 4 > 5 0 5 > 6 1 6 > 7 0 7 > 8 1 8 > 9 0 9 > 10 1 10 Firstly i want to create combinations from X2, for > example:combn(a$X2,2) It's ok, > but secondly> I would like to get combinations from those X2 numbers only , where > X1= 0. Could you help me? Thanks!> combn( a[a$X1==0, "X2"] ,2) [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [1,] 1 1 1 1 3 3 3 5 5 7 [2,] 3 5 7 9 5 7 9 7 9 9> > [[alternative HTML version deleted]]Please learn to post with a meaningful subject line and in plain text. The most excellent Posting Guide is a font of wisdom in other areas as well. As is the "Introduction to R" which should be studied in its entirety but for this case the section: "2.7 Index vectors; selecting and modifying subsets of a data set". Afore-mentioned posting guide: http://www.R-project.org/posting-guide.html -- David Winsemius, MD Alameda, CA, USA
Hi, Try this: dat1<-read.table(text=" 1?? 0? 1 2?? 1? 2 3?? 0? 3 4?? 1? 4 5?? 0? 5 6?? 1? 6 7?? 0? 7 8?? 1? 8 9?? 0? 9 10? 1 10 ",sep="",header=FALSE) ?dat2<-dat1[,-1] combn((subset(dat2,V2==0))$V3,2) ???? [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [1,]??? 1??? 1??? 1??? 1??? 3??? 3??? 3??? 5??? 5???? 7 [2,]??? 3??? 5??? 7??? 9??? 5??? 7??? 9??? 7??? 9???? 9 A.K. ----- Original Message ----- From: Dik?n Szabolcs Andr?s <dikanszabolcs at freemail.hu> To: R-help at r-project.org Cc: Sent: Sunday, August 19, 2012 8:14 PM Subject: [R] (no subject) Dear R Users! I'm new in R! I've got a data.frame. For example:a<-data.frame(cbind(? 0:1,? 1:10))? X1 X2 1? 0? 1 2? 1? 2 3? 0? 3 4? 1? 4 5? 0? 5 6? 1? 6 7? 0? 7 8? 1? 8 9? 0? 9 10? 1 10 Firstly i want to create combinations from? X2, for example:combn(a$X2,2) It's ok, butsecondly I would like to get combinations from those X2 numbers only , where X1= 0. Could you help me? Thanks!? ? ? ? ? ??? [[alternative HTML version deleted]] ______________________________________________ R-help at 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.