Hi, Try: test2 <- as.data.frame(test,stringsAsFactors=FALSE) test2[,c(2:4)] <- lapply(test2[,c(2:4)],as.numeric) A.K.
On Friday, November 8, 2013 6:24 AM, Kuma Raj <pollar...@gmail.com> wrote: Beend, Thanks for that. Conversion of test to a data frame resulted in a factor. Is there a possibility to selectively convert to numeric? I have tried this code and that has not produced the intended result. test[, c(2:4)] <- sapply(test[, c(2:4)], as.numeric) On 8 November 2013 11:31, Berend Hasselman <b...@xs4all.nl> wrote: > > On 08-11-2013, at 10:40, Kuma Raj <pollar...@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 > > [[alternative HTML version deleted]] ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.