Learn R Programming

openair (version 0.7-0)

import: Generic data import for openair

Description

This function is mostly used to simplify the importing of csv and text file in openair. In particular it helps to get the date or date/time into the correct format. The file can contain either a date or date/time in a single column or a date in one column and time in another.

Usage

import(file = file.choose(), file.type = "csv",
    sep = ",", header.at = 1, data.at = 2, date = "date",
    date.format = "%d/%m/%Y %H:%M", time = NULL,
    time.format = NULL, tz.in = "GMT", tz.out = "GMT",
    na.strings = c("", "NA"), quote = """, ws = NULL,
    wd = NULL, correct.time = NULL, ...)

Arguments

file
The name of the file to be imported. Default, file = file.choose(), opens browser. Alternatively, the use of read.table (in utils) also allows this to be a character vector of a file path, connection or u
file.type
The file format, defaults to common csv (comma delimited) format, but also allows txt (tab delimited).
sep
Allows user to specify a delimiter if not , (csv) or TAB (txt). For example ; is sometimes used to delineate separate columns.
header.at
The file row holding header information or NULL if no header to be used.
data.at
The file row to start reading data from. When generating the data frame, the function will ignore all information before this row, and attempt to include all data from this row onwards.
date
Name of the field containing the date. This can be a date e.g. 10/12/2012 or a date-time format e.g. 10/12/2012 01:00.
date.format
The format of the date. This is given in R format according to strptime. For example, a date format such as 1/11/2000 12:00 (day/month/year hour:minutes) is given the format %d/%m/%Y %H:%M. See ex
time
The name of the column containing a time --- if there is one. This is used when a time is given in a separate column and date contains no information about time.
time.format
If there is a column for time then the time format must be supplied. Common examples include %H:%M (like 07:00) or an integer giving the hour, in which case the format is %H. Again, see examples b
tz.in
The time zone of the data being read. Most of the time this field can be ignored. However, one situation where it is useful to supply tz.in is if the original data considered daylight saving time i.e. there is an hour missing in s
tz.out
The time zone of the output to be used by openair functions.
na.strings
Strings of any terms that are to be interpreted as missing (NA). For example, this might be -999, or n/a and can be of several items.
quote
String of characters (or character equivalents) the imported file may use to represent a character field.
ws
Name of wind speed field if present if different from ws e.g. ws = "WSPD".
wd
Name of wind direction field if present if different from "wd" e.g. wd = "WDIR".
correct.time
Numerical correction (in seconds) for imported date. Default NULL turns this option off. This can be useful if the hour is represented as 1 to 24 (rather than 0 to 23 assumed by R). In which case correct.time = -3600
...
Other arguments passed to read.table.

Value

  • A data frame formatted for openair use.

Details

The function uses strptime to parse dates and times. Users should consider the examples for use of these formats. import will also ensure wind speed and wind direction are correctly labelled (i.e. "ws", "wd") if ws or wd are given.

See Also

Dedicated import functions available for selected file types, e.g. : importAURN, importAURNCsv, importKCL, importADMS, etc.

Examples

Run this code
## Note that more examples are given in the openair manual

## import a file with date in format 1/12/2000 10:00 (default format dd/mm/YYYY HH:MM) called "DATE"
thedata <- import("~/data/testdata.csv", date = "DATE")

## import a file with date in format 12/1/2000 10:00 (USA format mm/dd/YYYY HH:MM) called "DATE"
thedata <- import("~/data/testdata.csv", date = "DATE", date.format = "%m/%d/%Y %H:%M")

## import a file where date and time are in separate columns with
## names "date" (called "Date" in format dd/mm/YYYY) and "time"
## (called "Time" in format "HH:MM")
thedata <- import("~/data/testdata.csv", date = "Date", date.format = "%d/%m/%Y",
time = "Time", time.format = "%H:%M")

Run the code above in your browser using DataLab