The Art of R Programming
This also has the advantage of not destroying the names inwu, in case they are needed later. If they will not be needed later, w ...
$means [1] 3 $that [1] 4 40 ... Here’s code to present the list in alphabetical order by word: 1 # sorts wrdlst, the output of f ...
We can sort by word frequency in a similar manner. 1 # orders the output of findwords() by word frequency 2 freqwl <- functio ...
[1] 9162933 $of [1] 11 21 42 56 $output [1] 12 19 39 57 Yep, ordered from least to most frequent. We can also do a plot of the m ...
4.4.3 Extended Example: Back to the Abalone Data..................... Let’s use thelapply()function in our abalone gender exampl ...
[1] 5 [[1]]$v [1] 12 [[2]] [[2]]$w [1] 13 > length(a) [1] 2 This code makesainto a two-component list, with each component it ...
5 DATA FRAMES On an intuitive level, adata frameis like a matrix, with a two-dimensional rows-and- columns structure. However, i ...
5.1 Creating Data Frames....................................................... To begin, let’s take another look at our simple ...
Consider three ways to access the first column of our data frame above: d[[1]],d[,1], andd$kids. Of these, the third would gener ...
5 2.3 1.0 3.3 6 3.3 3.7 4.0 5.2 Other Matrix-Like Operations................................................ Various matrix oper ...
19 4 4.0 4.0 22 4 4.0 4.0 25 4 4.0 3.3 29 4 3.0 3.7 5.2.2 More on Treatment of NA Values................................. Suppos ...
>d4 kids states 1 Jack CA 2 <NA> MA 3 Jillian MA 4 John <NA> > complete.cases(d4) [1] TRUE FALSE TRUE FALSE &g ...
3 4.0 4.0 4.0 0.0 4 2.3 0.0 3.3 -2.3 5 2.3 1.0 3.3 -1.3 6 3.3 3.7 4.0 0.4 The new name is rather unwieldy: It’s long, and it has ...
5.2.5 Extended Example: A Salary Study............................... In a study of engineers and programmers, I considered the ...
I was particularly interested in three occupations and thus extracted subdata frames for them to make their analyses more conven ...
This merges data framesxandy. It assumes that the two data frames have one or more columns with names in common. Here’s an examp ...
3 Jillian MA 4 John HI d2a <- rbind(d2,list(15,"Jill")) d2a ages kids 1 12 Jack 2 10 Jill 3 7 Lillian 4 15 Jill merge(d1,d2a ...
Here, I specified that the fileDAhad fields separated by commas. The function then reported the number of fields in each record ...
For instance, with our previous example, we can uselapplyas follows: d kids ages 1 Jack 12 2 Jill 10 dl <- lapply(d,sort) dl ...
We can usesapply()to fit eight single-predictor models—one for each of the eight variables other than gender in this data set—al ...
«
2
3
4
5
6
7
8
9
10
11
»
Free download pdf