[R] Remove a column of a matrix with unnamed column header

Berend Hasselman bhh at xs4all.nl
Fri Nov 8 11:31:57 CET 2013


On 08-11-2013, at 10:40, Kuma Raj <pollaroid at gmail.com> wrote:

> I have a matrix names test which I want to convert to a data frame. When I
> use a command  test2<-as.data.frame(test) it is executed without a problem.
> But when I want to browse the content I receive an error message "Error in
> data.frame(outcome = c("cardva", "respir", "cereb", "neoplasm",  :
> duplicate row.names: Estimate" . The problem is clearly due to a duplicate
> in  row name . But I am unable to remove this column. I need help on how to
> remove this specific column that has essentially no column header name.
> dput of the matrix is here:
> 
>> dput(test)
> structure(c("cardva", "respir", "cereb", "neoplasm", "ami", "ischem",
> "heartf", "pneumo", "copd", "asthma", "dysrhy", "diabet",
> "0.00259492159959046",
> "0.00979775441709427", "0.00103414632535868", "0.00486468139227382",
> "0.0164825543879707", "0.0116647168053943", "-0.0012137908515233",
> "0.00730433232907741", "0.00355583994565985", "0.000712387285735019",
> "-0.00103763671307935", "0.00981500221106926", "0.00325476724733837",
> "0.0049232113728293", "0.00520118026087645", "0.00386848394426742",
> "0.00688121694253705", "0.00585772614064902", "0.00564983058883797",
> "0.0061328202328586", "0.0108212194251692", "0.0173804438930357",
> "0.00867931407250442", "0.0106638104533486", "0.425323120845664",
> "0.0466180768654915", "0.842402292743715", "0.208609687427072",
> "0.0166336682608816", "0.0464833846710956", "0.8299010611324",
> "0.233685747699204", "0.742469001175026", "0.967306766450795",
> "0.904840885401235", "0.357394700741248"), .Dim = c(12L, 4L), .Dimnames =
> list(
>    c("Estimate", "Estimate", "Estimate", "Estimate", "Estimate",
>    "Estimate", "Estimate", "Estimate", "Estimate", "Estimate",
>    "Estimate", "Estimate"), c("outcome", "beta", "se", "pval"
>    )))
> 
>> test2<-as.data.frame(test)
>> test2
> Error in data.frame(outcome = c("cardva", "respir", "cereb", "neoplasm",  :
>  duplicate row.names: Estimate

rownames(test) <- NULL

Berend



More information about the R-help mailing list