[R] Elements of Sets as dataframe column names

Neha Aggarwal aggarwalneha2000 at gmail.com
Tue Mar 20 04:24:27 CET 2018

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

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?


	[[alternative HTML version deleted]]

More information about the R-help mailing list