Oops, didn't translate that function correctly: has_values<-function(x,values) { if(is.list(x)) { return(sum(unlist(lapply(svlist, function(x,values) return(all(values %in% x)),values)))) } } Jim On Wed, Jul 20, 2016 at 7:18 PM, Jim Lemon <drjimlemon at gmail.com> wrote:> Hi sri, > Maybe something like this? > > has_values<-function(x,values) { > if(is.list(x)) { > return(sum(unlist(lapply(svlist, > function(x,values) return(all(values %in% x)),c(11,12))))) > } > } > > svlist<-list(a=c(11,15,12,25), > b=c(11,12), > c=c(15,25), > d=c(134,45,56), > e=46, > f=c(45,56), > g=c(15,12), > h=c(66,45,56,24,14,11,25,12,134)) > > has_values(svlist,c(11,12)) > > Jim > > On Tue, Jul 19, 2016 at 8:59 PM, sri vathsan <srivibish at gmail.com> wrote: >> Hi, >> >> I have a data frame like below. >> 11,15,12,25 >> 11,12 >> 15,25 >> 134,45,56 >> 46 >> 45,56 >> 15,12 >> 66,45,56,24,14,11,25,12,134 >> >> I want to identify the frequency of pairs/triplets or higher that occurs in >> the data. Say for example, in above data the occurrence of pairs looks like >> below >> >> item No of occurrence >> 11,12 3 >> 11,25 2 >> 15,12 2 >> 15,25 2 >> . >> . >> 45,56 3 >> 134,45,56 2 >> >> ....and so on >> >> I am trying to write R code for the above and I am finding difficulty to >> approach this. Looking forward some help. >> >> Thanks! >> >> -- >> >> Regards, >> Srivathsan.K >> >> [[alternative HTML version deleted]] >> >> ______________________________________________ >> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see >> 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.
What you show cannot be a data.frame. Using what you gave, this should help you along: x <- c(11,15,12,25, 11,12, 15,25, 134,45,56, 46, 45,56, 15,12, 66,45,56,24,14,11,25,12,134) table(x) On Wed, 20 Jul 2016 at 11:44 Jim Lemon <drjimlemon at gmail.com> wrote:> Oops, didn't translate that function correctly: > > has_values<-function(x,values) { > if(is.list(x)) { > return(sum(unlist(lapply(svlist, > function(x,values) return(all(values %in% x)),values)))) > } > } > > Jim > > On Wed, Jul 20, 2016 at 7:18 PM, Jim Lemon <drjimlemon at gmail.com> wrote: > > Hi sri, > > Maybe something like this? > > > > has_values<-function(x,values) { > > if(is.list(x)) { > > return(sum(unlist(lapply(svlist, > > function(x,values) return(all(values %in% x)),c(11,12))))) > > } > > } > > > > svlist<-list(a=c(11,15,12,25), > > b=c(11,12), > > c=c(15,25), > > d=c(134,45,56), > > e=46, > > f=c(45,56), > > g=c(15,12), > > h=c(66,45,56,24,14,11,25,12,134)) > > > > has_values(svlist,c(11,12)) > > > > Jim > > > > On Tue, Jul 19, 2016 at 8:59 PM, sri vathsan <srivibish at gmail.com> > wrote: > >> Hi, > >> > >> I have a data frame like below. > >> 11,15,12,25 > >> 11,12 > >> 15,25 > >> 134,45,56 > >> 46 > >> 45,56 > >> 15,12 > >> 66,45,56,24,14,11,25,12,134 > >> > >> I want to identify the frequency of pairs/triplets or higher that > occurs in > >> the data. Say for example, in above data the occurrence of pairs looks > like > >> below > >> > >> item No of occurrence > >> 11,12 3 > >> 11,25 2 > >> 15,12 2 > >> 15,25 2 > >> . > >> . > >> 45,56 3 > >> 134,45,56 2 > >> > >> ....and so on > >> > >> I am trying to write R code for the above and I am finding difficulty to > >> approach this. Looking forward some help. > >> > >> Thanks! > >> > >> -- > >> > >> Regards, > >> Srivathsan.K > >> > >> [[alternative HTML version deleted]] > >> > >> ______________________________________________ > >> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > >> 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 at r-project.org mailing list -- To UNSUBSCRIBE and more, see > 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]]
Hi all, I understand this is not a data frame but an individual variable from the data frame which is a list. Since, I need to work on this particular variable I just added here as a sample data. Jim, your code solved the purpose.Thanks! Regards, Srivathsan On Wed, Jul 20, 2016 at 4:29 PM, Ulrik Stervbo <ulrik.stervbo at gmail.com> wrote:> What you show cannot be a data.frame. Using what you gave, this should > help you along: > > x <- c(11,15,12,25, 11,12, 15,25, 134,45,56, 46, 45,56, 15,12, > 66,45,56,24,14,11,25,12,134) > table(x) > > On Wed, 20 Jul 2016 at 11:44 Jim Lemon <drjimlemon at gmail.com> wrote: > >> Oops, didn't translate that function correctly: >> >> has_values<-function(x,values) { >> if(is.list(x)) { >> return(sum(unlist(lapply(svlist, >> function(x,values) return(all(values %in% x)),values)))) >> } >> } >> >> Jim >> >> On Wed, Jul 20, 2016 at 7:18 PM, Jim Lemon <drjimlemon at gmail.com> wrote: >> > Hi sri, >> > Maybe something like this? >> > >> > has_values<-function(x,values) { >> > if(is.list(x)) { >> > return(sum(unlist(lapply(svlist, >> > function(x,values) return(all(values %in% x)),c(11,12))))) >> > } >> > } >> > >> > svlist<-list(a=c(11,15,12,25), >> > b=c(11,12), >> > c=c(15,25), >> > d=c(134,45,56), >> > e=46, >> > f=c(45,56), >> > g=c(15,12), >> > h=c(66,45,56,24,14,11,25,12,134)) >> > >> > has_values(svlist,c(11,12)) >> > >> > Jim >> > >> > On Tue, Jul 19, 2016 at 8:59 PM, sri vathsan <srivibish at gmail.com> >> wrote: >> >> Hi, >> >> >> >> I have a data frame like below. >> >> 11,15,12,25 >> >> 11,12 >> >> 15,25 >> >> 134,45,56 >> >> 46 >> >> 45,56 >> >> 15,12 >> >> 66,45,56,24,14,11,25,12,134 >> >> >> >> I want to identify the frequency of pairs/triplets or higher that >> occurs in >> >> the data. Say for example, in above data the occurrence of pairs looks >> like >> >> below >> >> >> >> item No of occurrence >> >> 11,12 3 >> >> 11,25 2 >> >> 15,12 2 >> >> 15,25 2 >> >> . >> >> . >> >> 45,56 3 >> >> 134,45,56 2 >> >> >> >> ....and so on >> >> >> >> I am trying to write R code for the above and I am finding difficulty >> to >> >> approach this. Looking forward some help. >> >> >> >> Thanks! >> >> >> >> -- >> >> >> >> Regards, >> >> Srivathsan.K >> >> >> >> [[alternative HTML version deleted]] >> >> >> >> ______________________________________________ >> >> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see >> >> 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 at r-project.org mailing list -- To UNSUBSCRIBE and more, see >> 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. >> >-- Regards, Srivathsan.K Phone : 9600165206 [[alternative HTML version deleted]]