Learn R Programming

lessR (version 1.5.2)

rad: Read, Attach and Display Contents of a csv File

Description

Reads the contents of the specified csv data file into an R dataframe called mydata. Identifies the file by either browsing for the file on the local computer system, or as indicated by a path name or a web URL. Then attaches and lists the first and last three rows of data as well as the variable names and the dimensions of the resulting data frame. The purpose of rad is to save some keyboard entry, speeding up the process of reading a csv data file and reducing entry mistakes.

Usage

rad(ref=NULL, ...)

Arguments

ref
File reference, either null to specify the default of code{file.choose()} to browse for the csv data file, or a full path name or web URL, included in quotes. A URL begins with http://.
...
Other parameter values consistent with the usual read.csv function, such as row.names and header.

Details

One way to create a csv data file is with MS Excel or other worksheet application. Place the variable names in the first row of the worksheet. Each column of the worksheet contains the data for the corresponding variable. Each subsequent row contains the data for a specific observation, such as for a person or a company.

All numeric data should be displayed in the General format, so that the only non-digit character for a numeric data value is a decimal point. The General format removes all dollar signs and commas, for example, leaving only the pure number, stripped of these extra characters which R will not properly read as part of a numeric data value.

To create the csv file from a worksheet, under the File option, do a Save As and choose the csv format.

---

Given a csv data file, read the data into an R data frame called mydata with rad, which first invokes one of two R statements. Call with no arguments, as in rad(), to invoke:

mydata <- read.csv(file.choose()) Or, call with non-null ref option, rad("file_reference"), to invoke:

mydata <- read.csv("file_reference") Then, rad invokes the subsequent R statements: attach(mydata, warn.conflicts=FALSE), head(mydata, n=3) and tail(mydata, n=3). Output of these statements is directed to the console. Also listed are the R statements invoked by rad.

See Also

read.csv, attach, head, tail.

Examples

Run this code
# to browse for a csv data file on the computer system, invoke rad with 
# the ref argument empty, which, in turn, invokes read.csv(file.choose()),
# and then automatically invokes the attach, head and tail statements
# rad()

# same as above, but include standard read.csv options to indicate 
#  no variable names in first row of the csv data file and then 
#  provide the names
# rad(header=FALSE, col.names=c("X", "Y"))

# read a csv data file from the web
# then attach and list variable names and some values
rad("http://web.pdx.edu/~gerbing/data/twogroup.csv")

Run the code above in your browser using DataLab