Right way to convert data.frame to a numeric matrix, when df also contains strings?

前端 未结 6 674
说谎
说谎 2020-12-22 19:34

I have a data frame taken from a .csv-file which contains numeric and character values. I want to convert this data frame into a matrix. All containing information is number

6条回答
  •  悲哀的现实
    2020-12-22 19:53

    I had the same problem and I solved it like this, by taking the original data frame without row names and adding them later

    SFIo <- as.matrix(apply(SFI[,-1],2,as.numeric))
    row.names(SFIo) <- SFI[,1]
    

提交回复
热议问题