How to convert a 'string numeric' column into pure numeric in R matrix

前端 未结 1 1638
深忆病人
深忆病人 2021-01-24 03:49

Giving the following data:

      GOBPID                    Term     col1 col2 col3 col4 col5
1 GO:0001659 temperature_homeostasis 3.496906    0    0    0    0
2          


        
相关标签:
1条回答
  • 2021-01-24 04:15

    dat is a data.frame, not a matrix. The columns of a data.frame can have different types. In your example, the type of col1-5 is already numeric. Try it yourself:

    > dat <- read.table("http://dpaste.com/1486837/plain/",header=TRUE)
    > sapply(dat, class)
       GOBPID      Term      col1      col2      col3      col4      col5 
     "factor"  "factor" "numeric" "integer" "integer" "integer" "integer" 
    > dat[,3] + 1
    [1] 4.496906 4.226069
    > dat[,4] + 1
    [1] 1 1
    
    0 讨论(0)
提交回复
热议问题