Importing csv file into R - numeric values read as characters

前端 未结 6 843
逝去的感伤
逝去的感伤 2020-12-01 01:26

I am aware that there are similar questions on this site, however, none of them seem to answer my question sufficiently.

This is what I have done so far:

I

6条回答
  •  有刺的猬
    2020-12-01 02:20

    Whatever algebra you are doing in Excel to create the new column could probably be done more effectively in R.

    Please try the following: Read the raw file (before any excel manipulation) into R using read.csv(... stringsAsFactors=FALSE). [If that does not work, please take a look at ?read.table (which read.csv wraps), however there may be some other underlying issue].

    For example:

       delim = ","  # or is it "\t" ?
       dec = "."    # or is it "," ?
       myDataFrame <- read.csv("path/to/file.csv", header=TRUE, sep=delim, dec=dec, stringsAsFactors=FALSE)
    

    Then, let's say your numeric columns is column 4

       myDataFrame[, 4]  <- as.numeric(myDataFrame[, 4])  # you can also refer to the column by "itsName"
    


    Lastly, if you need any help with accomplishing in R the same tasks that you've done in Excel, there are plenty of folks here who would be happy to help you out

提交回复
热议问题