fwfdat <- read.fwf(“ﬁle.txt”, width = c(3, 5, ...)) Use width = list(c(3,5,..), c(5,7,..)) for multiple rows per subject
Manipulating data in Rn Objectsn Classesn Various data objects
Objectsn Just about everything named in R is an objectn An object is a container that n knows its class (eg, I have numbers inside!). n has contents (eg, Actual numbers).
Examples of objectsn data, which you use for analysis (various classes)n functions, which perform analysis (function class)n results, which come out of analysis (various classes)
Classes of data values inside data objectsn Numeric: Continuous variablesn Factor: Categorical variablesn Logical: TRUE/FALSE binary variablesn etc...
Class?n An object’s class tells R how the object should be handled.n For example, summarizing data should work differently for numbers and categories!
Data objectsn Vector (contains single class of data values)n List (contains multiple classes of data values)
Data objectsn Vector (contains single class of data values) n Array including Matrixn List (contains multiple classes of data values) n Data frame
Vectorn Smallest building block of data objectsn Single dimensionn Combination of values of same classn vec1 <- c(2013, 2, 15, -10) # combinen vec2 <- 1:16 # integers 1 to 16
Arrayn Vector folded into a multidimensional structuren 2-dimensional array is a matrixn vec3 <- 1:16n dim(vec3) <- c(4, 4) # 4 x 4 structuren dim(vec3) <- c(2, 2, 4) # 2 x 2 x 4 structuren arr1 <- array(1:60, dim = c(3,4,5))
Listn Combination of any values or objectsn Can contain objects of multiple classesn eg, a list of two vectors, a matrix, three arraysn list1 <- list(ﬁrst = 1:17, second = matrix(letters, 13,2))n list2 <- list(alpha = c(1,4,5,7), beta = c("h","s","p","h"))
Data framen Special case of a listn List of same-length vectors vertically alignedn df1 <- data.frame(list2)n list3 <- list(small = letters, large = LETTERS, number = 1:26)n df2 <- data.frame(list3)