Hi, I am newbie to R and working on result presentation? My Input table is in following format A B C D X T C K Z U Z M E V Z R Z U Z M E V P R I need to present my result in the following way. Colum3 C A B D X T K Column3 Z Z U M E V R Z U M Column3 P E V R How can i implement it? Thanks -- View this message in context: http://r.789695.n4.nabble.com/How-to-Group-Categorical-data-in-R-tp4477622p4477622.html Sent from the R help mailing list archive at Nabble.com.
Hi Manish, Try # data set x <- structure(list(V1 = structure(c(1L, 3L, 4L, 2L, 4L, 2L), .Label c("A", "E", "X", "Z"), class = "factor"), V2 = structure(c(1L, 2L, 3L, 4L, 3L, 4L), .Label = c("B", "T", "U", "V"), class = "factor"), V3 = structure(c(1L, 1L, 3L, 3L, 3L, 2L), .Label = c("C", "P", "Z"), class = "factor"), V4 = structure(c(1L, 2L, 3L, 4L, 3L, 4L), .Label = c("D", "K", "M", "R"), class = "factor")), .Names = c("V1", "V2", "V3", "V4"), class = "data.frame", row.names = c(NA, -6L )) # result lapply(split(x, x$V3), "[", c(1, 2, 4)) See ?lapply, ?split and ?"[" for more information. HTH, Jorge.- On Fri, Mar 16, 2012 at 4:43 AM, Manish Gupta <> wrote:> Hi, > > I am newbie to R and working on result presentation? My Input table is in > following format > > A B C D > X T C K > Z U Z M > E V Z R > Z U Z M > E V P R > > I need to present my result in the following way. > > Colum3 C > A B D > X T K > > Column3 Z > Z U M > E V R > Z U M > > Column3 P > E V R > > How can i implement it? > > Thanks > > -- > View this message in context: > http://r.789695.n4.nabble.com/How-to-Group-Categorical-data-in-R-tp4477622p4477622.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > 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]]
How about this --? ##Assumes you have read your data into data frame "Msg17" ## Capture unique values from data file's Column 3 Col3 <- unique(Msg17$V3) #Captures length of the unique value vector LCol3 <- length(Col3) ## Loop to sequentially select rows with the unique Col3 values for (i in 1:LCol3) { print(paste("Column", Col3[i])) print(Msg17[Msg17$V3==Col3[i],-3]) } Good luck! -- View this message in context: http://r.789695.n4.nabble.com/How-to-Group-Categorical-data-in-R-tp4477622p4481247.html Sent from the R help mailing list archive at Nabble.com.
It is working fine. Thanks -- View this message in context: http://r.789695.n4.nabble.com/How-to-Group-Categorical-data-in-R-tp4477622p4483565.html Sent from the R help mailing list archive at Nabble.com.
If there are some unique value in each column. How to look up in R? -- View this message in context: http://r.789695.n4.nabble.com/How-to-Group-Categorical-data-in-R-tp4477622p4633235.html Sent from the R help mailing list archive at Nabble.com.
This is not really enough information. PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Have you looked at ?unique John Kane Kingston ON Canada> -----Original Message----- > From: mandecent.gupta at gmail.com > Sent: Wed, 13 Jun 2012 04:03:00 -0700 (PDT) > To: r-help at r-project.org > Subject: Re: [R] How to Group Categorical data in R? > > If there are some unique value in each column. How to look up in R? > > > > -- > View this message in context: > http://r.789695.n4.nabble.com/How-to-Group-Categorical-data-in-R-tp4477622p4633235.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > 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.____________________________________________________________ FREE 3D MARINE AQUARIUM SCREENSAVER - Watch dolphins, sharks & orcas on your desktop!