[R] split and common variables

arun smartpink111 at yahoo.com
Mon Jun 3 17:09:27 CEST 2013


Hi,

It is not clear.
dta1<-do.call(data.frame,dta)
dta2<-dta1[complete.cases(dta1),]
dta2[,-3]<-lapply(dta2[,-3],as.character)
lstdta2<-split(dta2,dta2$place)
library(plyr)
join_all(lapply(lstdta2,`[`,-1),by="name",type="inner") #none of them are common
#[1] name  value value value value value
#<0 rows> (or 0-length row.names)


A.K.


----- Original Message -----
From: Nico Met <nicomet80 at gmail.com>
To: R help <r-help at r-project.org>
Cc: 
Sent: Monday, June 3, 2013 9:41 AM
Subject: [R] split and common variables

Dear all,

I would like to split the data based on the "place" and then would like to
see how many "names" were common in place with corresponding "value" .

Please find a demo file.

Thanks for your expert comment

best

Nico

> dput(dta)
structure(list(place = structure(c(3L, 2L, 5L, 6L, 4L, 3L, 2L,
5L, 6L, 4L, 2L, 5L, 6L, 4L, 2L, 5L, 6L, 4L, 2L, 3L, 2L, 5L, 6L,
4L, 3L, 2L, 5L, 6L, 4L, 5L, 6L, 4L, 5L, 6L, 1L), .Label = c("",
"GCKT", "IKLI", "KLOI", "PLRT", "POIV"), class = "factor"), name = structure
(c(2L,
3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 2L, 3L, 4L, 5L, 6L,
7L, 8L, 9L, 10L, 11L, 12L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L,
11L, 12L, 12L, 1L), .Label = c("", "P_CK23", "P_CK24", "P_CK25",
"P_CK26", "P_CK27", "P_CK28", "P_CK29", "P_CK30", "P_CK31", "P_CK32",
"P_CK33"), class = "factor"), value = c(5.9464, 6.0786, -4.5155,
15.0241, -38.1847, -0.0861, 1.2757, -23.9914, 9.5951, -11.128,
6.2826, 23.5218, 20.862, 3.1626, 6.242, -20.5348, -14.0126, -13.796,
15.3869, -15.7409, -8.1963, -14.4522, 3.2117, -1.2738, 14.3556,
-12.5337, 20.4308, -3.3227, -34.802, -11.1103, -9.7146, -35.9044,
-9.4303, -28.1949, NA)), .Names = c("place", "name", "value"), class = "data
.frame", row.names = c(NA,
35L))
>

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




More information about the R-help mailing list