mydata
. Identifies the file by either browsing for the file on the local computer system with rad()
, 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. In addition, perform an analysis of missing data, listing the number of missing values for each variable and for each observation.rad(ref=NULL, display=TRUE, show.R=FALSE, no.attach=FALSE,
n.cut=1, miss.show=30, miss.zero=FALSE, miss.matrix=FALSE,
format=c("csv", "SPSS"), ...)
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://
.TRUE
then do not attach the R data frame,
mydata
by default.n.cut
.csv
file, and as option can be an SPSS sav
file.read.csv
function, such as row.names and header.rad
reads csv
data files. One way to create a csv data file is by entering the data into a text editor. A more structured method is to use a worksheet application such as MS Excel, LibreOffice Calc. 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 in the worksheet 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 Excel, under the File option, do a Save As and choose the csv format.
MECHANICS
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
.
Because rad
calls the standard R function read.csv
, which just provides a wrapper for read.table
, the usual options that work with read.table
, such as row.names
also can be passed through rad
.
SPSS DATA
To read data in the SPSS .sav
format, rad
calls the read.spss
function from the foreign
package. To invoke this option, specify format="SPSS"
.
MISSING DATA
By default, rad
provides a list of each variable and each row with the display of the number of associated missing values, indicated by the standard R missing value code NA. When reading the data, R automatically sets any empty numeric and logical values as missing. Null character string values are left as null, unless the R na.strings=""
option is invoked. Of course any other valid value can be set to missing as well.
To not list the variable name or row name of variables or rows without missing data, invoke the miss.zero=FALSE
option, which can appreciably reduce the amount of output for large data sets. To view the entire data table in terms of 0's and 1's for non-missing and missing data, respectively, invoke the miss.matrix=TRUE
option.
read.csv
, attach
, head
, tail
.# 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
# also indicate that the first column is an ID field
# rad(header=FALSE, col.names=c("X", "Y"), row.names=1)
# 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