Greetings,

Does this exist somewhere in base and/or DataFrames: the ability to read
only selected columns from some text input?  Ideally, you could have each
output vector of a different type (Float64, Int, etc.).   (So it differs
from readdlm() in philosophy.)

A minimal implementation is below assuming space delimiters and Float64
types for all columns. (BTW, comments on this approach or improvements are
also very welcome.)

# selectively read specified columns from a file
# return tuple of vectors
# TODO: enable optional selection of types for each column
function readcols(file,idx...)
    const re_comment = r"#.*$"
    r = map( x -> Float64[] , idx )
    open(file) do f
for line in eachline(f)
    l = strip( replace(line, re_comment, "") )
    if length(l) > 0
c = split(l)
j = 1
 for i in idx
    push!(r[j], float(c[i]))
    j += 1
 end
    end
end
    end
    return r
end

Thanks!

Cameron

Reply via email to