Czerminski, Ryszard
2010-Mar-22 21:26 UTC
[R] sets package: converting a set to data frame?
I just started using nice package "sets" and I wonder if there are utilities to convert (some) sets to data frame (as in the example below)> library(sets) > a <- gset(elements = list(e('A', 0.1), e('B', 0.8))) > lst <- as.list(a) > nr <- length(lst) > rnames <- character() > for (i in 1:nr) rnames[i] <- lst[[i]] > df <- data.frame(row.names=rnames) > df$memberships <- attr(lst, 'memberships') > a{"A" [0.1], "B" [0.8]}> dfmemberships A 0.1 B 0.8>Best regards, Ryszard --- Ryszard Czerminski -------------------------------------------------------------------------- Confidentiality Notice: This message is private and may ...{{dropped:11}}
Henrique Dallazuanna
2010-Mar-22 21:39 UTC
[R] sets package: converting a set to data frame?
Try this: data.frame(row.names = unlist(a), gset_memberships(a)) On Mon, Mar 22, 2010 at 6:26 PM, Czerminski, Ryszard <Ryszard.Czerminski at astrazeneca.com> wrote:> I just started using nice package "sets" > and I wonder if there are utilities to convert (some) sets to data frame > (as in the example below) > >> library(sets) >> a <- gset(elements = list(e('A', 0.1), e('B', 0.8))) >> lst <- as.list(a) >> nr <- length(lst) >> rnames <- character() >> for (i in 1:nr) rnames[i] <- lst[[i]] >> df <- data.frame(row.names=rnames) >> df$memberships <- attr(lst, 'memberships') >> a > {"A" [0.1], "B" [0.8]} >> df > ?memberships > A ? ? ? ? 0.1 > B ? ? ? ? 0.8 >> > > Best regards, > Ryszard > --- > Ryszard Czerminski > > > -------------------------------------------------------------------------- > Confidentiality Notice: This message is private and may ...{{dropped:11}} > > ______________________________________________ > 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. >-- Henrique Dallazuanna Curitiba-Paran?-Brasil 25? 25' 40" S 49? 16' 22" O