[R] Help

André Luis Neves andrluis at ualberta.ca
Fri Nov 18 20:02:32 CET 2016


Dear,

I have the following list (mylist), in which I need to pass to the column 2
the name of the list itself.
So, running the follwing commands:

A= data.frame(1:2,3)
B= data.frame(1:4,3)
C= data.frame(c(1:2),c(4:5))
mylist=list(A=A,B=A,C=C)
lapply(mylist, setNames, paste(c("CaZyme")))

The output would be:
> lapply(mylist, setNames, paste(c("CaZyme")))
$A
  CaZyme NA
1      1  3
2      2  3

$B
  CaZyme NA
1      1  3
2      2  3

$C
  CaZyme NA
1      1  4
2      2  5
3      3  6

My question is:
How could I name the second column with the name of each dataframe of the
list, such that NA would be substitute for A, B and C, respectively.

Thank you very much,

Andre


-- 
Andre

	[[alternative HTML version deleted]]



More information about the R-help mailing list