readdlm(source)

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 cell array of numbers and strings is returned.

Examples

In the Julia programming language, the function readdlm(source, delim::Char, eol::Char) is used to read data from a file or a string and create a matrix or a cell array depending on the type of data present.

  1. Read data from a file with a specified delimiter and end-of-line character:

    julia> data = readdlm("data.csv", ',', '\n')
    3×2 Array{Any,2}:
    "1"   "John"
    "2"   "Jane"
    "3"   "Alice"

    This example reads data from the file "data.csv" using a comma as the delimiter and a newline character as the end-of-line character. The resulting matrix data contains the parsed values.

  2. Read data from a string with custom delimiter and end-of-line character:

    julia> string_data = "4 | Bob\n5 | Carol\n6 | Dave"
    julia> data = readdlm(string_data, '|', '\n')
    3×2 Array{Any,2}:
    "4 "   " Bob"
    "5 "   " Carol"
    "6 "   " Dave"

    In this example, the function reads data from a string string_data using the pipe symbol '|' as the delimiter and a newline character '\n' as the end-of-line character.

  3. Read numeric data from a file:
    julia> numeric_data = readdlm("numeric_data.txt", ',', '\n')
    3×2 Array{Float64,2}:
    1.0   2.0
    3.0   4.0
    5.0   6.0

    If all the data in the file can be parsed as numbers, the resulting matrix will have the appropriate numeric type.

Common mistake example:

julia> invalid_data = readdlm("data.csv", ',', '\n')
ERROR: ArgumentError: invalid delimiter character ","

In this example, an error occurs because the delimiter character ',' is not valid for the given data. Make sure to provide the correct delimiter that matches the structure of the data source.

Note: The function readdlm also has additional optional arguments (options) that allow for further customization, but they are not covered in these examples.

See Also

abspath, basename, chmod, countlines, cp, ctime, dirname, download, evalfile, expanduser, fdio, filemode, filesize, functionloc, gperm, homedir, include_string, isabspath, isblockdev, ischardev, isdir, isdirpath, isexecutable, isfifo, isfile, islink, ismount, ispath, isreadable, issetgid, issetuid, issticky, iswritable, joinpath, less, lstat, mkdir, mkpath, mktemp, mktempdir, mtime, mv, normpath, operm, poll_fd, poll_file, readall, readcsv, readdir, readdlm, readlines, readlink, realpath, relpath, rm, splitdir, splitdrive, splitext, stat, symlink, tempdir, tempname, touch, truncate, uperm, watch_file, writecsv,

User Contributed Notes

Add a Note

The format of note supported is markdown, use triple backtick to start and end a code block.

*Required Field
Details

Checking you are not a robot: