R: Read Ring Width File from CSV

csv2rwl {dplR} | R Documentation

## Read Ring Width File from CSV

### Description

This function reads in a file of ring widths (.rwl) from a text file with comma separated values (csv).

### Usage

    csv2rwl(fname,...)

### Arguments

`fname` | a `character` vector giving the file name of the csv file.
`...` | other arguments passed to `read.table`.

### Details

This is a simple wrapper to `read.table` that reads in a text file with ring-width data in "spreadsheet" format. I.e., with series in columns and the the years as rows. The first column should contain the years and each subsequent column should contain a tree-ring series. The series names should be in the first row of the file. The deafult for `NA` values are empty cells or as the character string `"NA"` but can also be set using the `na.strings` argument passed to `read.table`. E.g.,:

Year | Ser1A | Ser1B | Ser2A | Ser2B
1901 | NA | 0.45 | 0.43 | 0.24
1902 | NA | 0.05 | 0.00 | 0.07
1903 | 0.17 | 0.46 | 0.03 | 0.21
1904 | 0.28 | 0.21 | 0.54 | 0.41
1905 | 0.29 | 0.85 | 0.17 | 0.76
1906 | 0.56 | 0.64 | 0.56 | 0.31
1907 | 1.12 | 1.06 | 0.99 | 0.83
etc...

Note that this is a rudimentary convenience function that isn't doing anything sophisticated. It reads in a file, assigns the years to the row names and sets the class of the object to `c("rwl","data.frame")` which allows `dplR` to recognize it.

Although arguments can be passed to `read.table`, this is not designed to be a flexible function. As is the philosophy with `dplR`, modifying the code is easy should the user wish to read in a different style of text file (e.g., tab delimited). Typing `csv2rwl` at the `R` prompt will get the user started.

### Value

Function returns an object of class `c("rwl", "data.frame")` with the series in columns and the years as rows. The series IDs are the column names and the years are the row names.

### Author(s)

Andy Bunn

### See Also

`read.rwl`, `read.table`

### Examples

    library(utils)
    data(ca533)
    # write out a rwl file in a format that csv2rwl will understand
    tm <- time(ca533)
    foo <- data.frame(tm,ca533)
    # this is the temp file where foo will be written
    tmpName <- tempfile()
    write.csv(foo,file=tmpName,row.names=FALSE)
    # read it back in using csv2rwl
    bar <- csv2rwl(tmpName)
    # check to see if identical
    identical(ca533,bar)
    # delete temp file
    unlink(tmpName)

[Package dplR version 1.7.1 Index]