You have failed to tell us that you are using a package, presumably the
sets package.
What I believe you don't understand is that the underlying data structures
that represent sets are not what you think they are, but behave as you
expect through the package API. So unless the API gets you the names in the
form you want, you will have to write code to do this yourself. Based on
what you show above, various string handling functionality -- see, e.g.
?regexp and ?gsub or ?strsplit in base R or the stringr or stringi packages
which are likely easier to learn and use -- are how you could go about
this. Effort would be required to climb the larning curve, but I suspect
you would find it time well spent.
Cheers,
Bert
Bert Gunter
"The trouble with having an open mind is that people keep coming along and
sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
On Mon, Mar 19, 2018 at 8:24 PM, Neha Aggarwal <aggarwalneha2000 at
gmail.com>
wrote:
> Hello all,
>
> I have a set B and a dataframe df. I want to name the columns of the
> dataframe after the elements of the set B.
> For example, for set B with elements {{"P1"}, {"P2"},
{"P3", "P4"}} I want
> to create a new dataframe with 3 columns named {"P1"} and
{"P2"} and
> {"P3","P4"}.
>
> I tried colnames(df)<-(B). But it shows the elements as list, see below:
> > colnames(df)
> [1] "list(\"P1\")"
"list(\"P2\")" "list(\"P3\",
\"P4\")"
>
>
> Second part of my question is what is the bests command to extract the
> elements of a set?
>
>
> Thanks,
> Neha
>
> [[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.
>
[[alternative HTML version deleted]]