Converting non-standard file to .csv in R

时间:2015-05-04 18:18:35

标签: r file csv rstudio file-conversion

Some of the output files I use are non-standard, space delimited formats with non-standard extensions (.out) that only have meaning to a particular program I use. For example, I might get an output file for water budgets that looks like: waterbalance.out

I can open these files in Excel by opening the file as a space delimited file and starting import on row 3.

How can I read such file types into R so that I can convert to .csv?

enter image description here

1 个答案:

答案 0 :(得分:2)

假设您有一个空格分隔文件:

var mySorted = myArr.sorted { (a: MyStruct, b: MyStruct) in
    var c = currentTime
    if a.time > c && b.time > c {
        // both in the future
        return a.time < b.time
    }
    else if a.time < c && b.time < c {
        // both in the past
        return a.time > b.time
    }
    else if a.time > c {
        return true
    }
    return false
}

您可以为read.csv指定分隔符:

name grade percent
john 1 0.3
brian 2 0.25
joshua 5 1.1

此外,> read.csv("test.ssv", sep=" ") name grade percent 1 john 1 0.30 2 brian 2 0.25 3 joshua 5 1.10 中的fread能够自动解析:

data.table