Movatterモバイル変換


[0]ホーム

URL:


GitHub

Delimited Files

DelimitedFiles.readdlmMethod
readdlm(source, delim::AbstractChar, T::Type, eol::AbstractChar; header=false, skipstart=0, skipblanks=true, use_mmap, quotes=true, dims, comments=false, comment_char='#')

Read a matrix from the source where each line (separated byeol) gives one row, with elements separated by the given delimiter. The source can be a text file, stream or byte array. Memory mapped files can be used by passing the byte array representation of the mapped segment as source.

IfT is a numeric type, the result is an array of that type, with any non-numeric elements asNaN for floating-point types, or zero. Other useful values ofT includeString,AbstractString, andAny.

Ifheader istrue, the first row of data will be read as header and the tuple(data_cells, header_cells) is returned instead of onlydata_cells.

Specifyingskipstart will ignore the corresponding number of initial lines from the input.

Ifskipblanks istrue, blank lines in the input will be ignored.

Ifuse_mmap istrue, the file specified bysource is memory mapped for potential speedups if the file is large. Default isfalse. On a Windows filesystem,use_mmap should not be set totrue unless the file is only read once and is also not written to. Some edge cases exist where an OS is Unix-like but the filesystem is Windows-like.

Ifquotes istrue, columns enclosed within double-quote (") characters are allowed to contain new lines and column delimiters. Double-quote characters within a quoted field must be escaped with another double-quote. Specifyingdims as a tuple of the expected rows and columns (including header, if any) may speed up reading of large files. Ifcomments istrue, lines beginning withcomment_char and text followingcomment_char in any line are ignored.

Examples

julia> using DelimitedFilesjulia> x = [1; 2; 3; 4];julia> y = [5; 6; 7; 8];julia> open("delim_file.txt", "w") do io           writedlm(io, [x y])       endjulia> readdlm("delim_file.txt", '\t', Int, '\n')4×2 Matrix{Int64}: 1  5 2  6 3  7 4  8julia> rm("delim_file.txt")
DelimitedFiles.readdlmMethod
readdlm(source, delim::AbstractChar, eol::AbstractChar; options...)

If all data is numeric, the result will be a numeric array. If some elements cannot be parsed as numbers, a heterogeneous array of numbers and strings is returned.

DelimitedFiles.readdlmMethod
readdlm(source, delim::AbstractChar, T::Type; options...)

The end of line delimiter is taken as\n.

Examples

julia> using DelimitedFilesjulia> x = [1; 2; 3; 4];julia> y = [1.1; 2.2; 3.3; 4.4];julia> open("delim_file.txt", "w") do io           writedlm(io, [x y], ',')       end;julia> readdlm("delim_file.txt", ',', Float64)4×2 Matrix{Float64}: 1.0  1.1 2.0  2.2 3.0  3.3 4.0  4.4julia> rm("delim_file.txt")
DelimitedFiles.readdlmMethod
readdlm(source, delim::AbstractChar; options...)

The end of line delimiter is taken as\n. If all data is numeric, the result will be a numeric array. If some elements cannot be parsed as numbers, a heterogeneous array of numbers and strings is returned.

Examples

julia> using DelimitedFilesjulia> x = [1; 2; 3; 4];julia> y = [1.1; 2.2; 3.3; 4.4];julia> open("delim_file.txt", "w") do io           writedlm(io, [x y], ',')       end;julia> readdlm("delim_file.txt", ',')4×2 Matrix{Float64}: 1.0  1.1 2.0  2.2 3.0  3.3 4.0  4.4julia> z = ["a"; "b"; "c"; "d"];julia> open("delim_file.txt", "w") do io           writedlm(io, [x z], ',')       end;julia> readdlm("delim_file.txt", ',')4×2 Matrix{Any}: 1  "a" 2  "b" 3  "c" 4  "d"julia> rm("delim_file.txt")
DelimitedFiles.readdlmMethod
readdlm(source, T::Type; options...)

The columns are assumed to be separated by one or more whitespaces. The end of line delimiter is taken as\n.

Examples

julia> using DelimitedFilesjulia> x = [1; 2; 3; 4];julia> y = [5; 6; 7; 8];julia> open("delim_file.txt", "w") do io           writedlm(io, [x y])       end;julia> readdlm("delim_file.txt", Int64)4×2 Matrix{Int64}: 1  5 2  6 3  7 4  8julia> readdlm("delim_file.txt", Float64)4×2 Matrix{Float64}: 1.0  5.0 2.0  6.0 3.0  7.0 4.0  8.0julia> rm("delim_file.txt")
DelimitedFiles.readdlmMethod
readdlm(source; options...)

The columns are assumed to be separated by one or more whitespaces. The end of line delimiter is taken as\n. If all data is numeric, the result will be a numeric array. If some elements cannot be parsed as numbers, a heterogeneous array of numbers and strings is returned.

Examples

julia> using DelimitedFilesjulia> x = [1; 2; 3; 4];julia> y = ["a"; "b"; "c"; "d"];julia> open("delim_file.txt", "w") do io           writedlm(io, [x y])       end;julia> readdlm("delim_file.txt")4×2 Matrix{Any}: 1  "a" 2  "b" 3  "c" 4  "d"julia> rm("delim_file.txt")
DelimitedFiles.writedlmFunction
writedlm(f, A, delim='\t'; opts)

WriteA (a vector, matrix, or an iterable collection of iterable rows) as text tof (either a filename string or anIO stream) using the given delimiterdelim (which defaults to tab, but can be any printable Julia object, typically aChar orAbstractString).

For example, two vectorsx andy of the same length can be written as two columns of tab-delimited text tof by eitherwritedlm(f, [x y]) or bywritedlm(f, zip(x, y)).

Examples

julia> using DelimitedFilesjulia> x = [1; 2; 3; 4];julia> y = [5; 6; 7; 8];julia> open("delim_file.txt", "w") do io           writedlm(io, [x y])       endjulia> readdlm("delim_file.txt", '\t', Int, '\n')4×2 Matrix{Int64}: 1  5 2  6 3  7 4  8julia> rm("delim_file.txt")

Settings


This document was generated withDocumenter.jl version 1.8.0 onWednesday 9 July 2025. Using Julia version 1.11.6.


[8]ページ先頭

©2009-2025 Movatter.jp