[R] Elements of Sets as dataframe column names
Jim Lemon
drjimlemon at gmail.com
Tue Mar 20 22:29:06 CET 2018
Hi Neha,
>From your message I think that you might get what you want with:
names(df)<-unlist(B)
However, the "sets" package might handle lists differently.
Jim
On Tue, Mar 20, 2018 at 2: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.
More information about the R-help
mailing list