R: `ID : Coercing LHS to a list` in adding an ID column, why?
It's throwing a warning, as the results of transpose t()
are a matrix. Matricies don't have accessible column names. You have to coerce the matrix to a data frame before you make the ID assignment, using as.data.frame()
This works.
Sinus<-c(1,0,0,0,0,0,12)
ArrAHB<-c(1,0,0,0.1,0,0,20.9)
Labels<-c("N11.1","N22.2","N33.1","N44.1","N21.1","N31.1","N32.1")
ID<-c("Sinus","Arr/AHB")
data.female<-data.frame(Sinus,ArrAHB,row.names=Labels)
data.female<-as.data.frame(t(data.female))
data.female$ID<-ID
Remember that data frames are defined column-wise and not row-wise. A data frame definition should be by columns.
I know this is late but I ran across the same problem. You can do this:
data.female <- cbind(data.female, ID)