Convert Factors in 2 Data Frames of a List into Numeric

后端 未结 1 1757
别跟我提以往
别跟我提以往 2021-01-26 14:10

I am having trouble converting the columns of 2 data frames in a list to numeric. Right now both data frames have 2 columns consisting of factors. I want to convert them to nu

相关标签:
1条回答
  • 2021-01-26 14:38

    You need to use lapply. do a str on "b"

    str(b)
    

    This will let you know you have a list of 2 of 2 data.frames.

    So you need to use lapply along with sapply, to preserve the data structure

    lapply(b, function(x) sapply(x, function(x) as.numeric(as.character(x))))
    

    You have D/N in your factor, which will be converted to NAs and also the list entries that are blank/empty

    0 讨论(0)
提交回复
热议问题