
上QQ阅读APP看书,第一时间看更新
How it works...
Let's break down the last complex statement in step 5, piece-by-piece, starting from the innermost portion and working outwards. First, let's read the file line by line:
x <- readLines("varlabels.txt")
Each line needs to be split at the string -. The spaces are important, so we don't split hyphenated words (such as in line 11). This results in each line split into two parts as a
vector of strings, and the vectors stored in a single list:
y <- strsplit(x, " - ")
Now, we stack these vectors together to make a matrix of strings, where the first column
is the variable name and the second column is the description of the variable:
labels <- do.call(rbind, y)