[R] convert matrix to dataframe with repeating row names
Richard.Cotton at hsl.gov.uk
Richard.Cotton at hsl.gov.uk
Mon Oct 20 11:29:19 CEST 2008
> I have a matrix x with repeating row names.
> zz<-matrix(0,4,4)
>
> rownames(zz)=c("a","a","b","b")
>
> data.frame(zz) (?)
The row names on a data frame should be unique. You can try
as.data.frame(xx, row.names=FALSE) to convert zz to be a data frame. If
you need the row name information, add it as a column in the data frame,
e.g. mydataframe$rnames <- rownames(zz). (Note to R-Core: the
documentation for as.data.frame doesn't mention the usage of
row.names=FALSE to ignore row names, but it seems to work consistently.
Does the help page for as.data.frame need updating?)
> lm(as.formula(paste("final_dat[,5]~",paste(colnames(x),collapse="+"))),x
> )
>
> this gives me a error
> Error in model.frame.default(formula =
> as.formula(paste("final_dat[,5]~", :
>
> 'data' must be a data.frame, not a matrix or an array
I suspect that if you try class(x), it will be a matrix, not the requisite
data frame.
Regards,
Richie.
Mathematical Sciences Unit
HSL
------------------------------------------------------------------------
ATTENTION:
This message contains privileged and confidential inform...{{dropped:20}}
More information about the R-help
mailing list