10.07.2015 Views

Using R for Introductory Statistics : John Verzani

Using R for Introductory Statistics : John Verzani

Using R for Introductory Statistics : John Verzani

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Bivariate data 69> colnames(x) = c("buckled","unbuckled")> xbuckled unbuckledbuckled 56 8unbuckled 2 16The dimnames() function can set both at once and allows us to specify variable names. Alist is used to specify these, as made by list(). Lists are discussed further in Chapter 4. Forthis usage, the variable name and values are given in name=value <strong>for</strong>mat. The rowvariable comes first, then the column.> tmp = c("unbuckled","buckled") # less typing> dimnames(x) = list(parent=tmp,child=tmp) # uses anamed list> xchildparent unbuckled buckledunbuckled 56 8buckled 2 16If the matrix is made with rbind(), then names <strong>for</strong> the row vectors can be specified inname=value <strong>for</strong>mat. Furthermore, column names will come from the vectors if present.> x = c(56,8); names(x) = c("unbuckled","buckled")> y = c(2,16)> rbind(unbuckled=x,buckled=y) # names rows, columnscome from xunbuckled buckledunbuckled 56 8buckled 2 163.1.2 Making two-way tables from unsummarized dataWith unsummarized data, two-way tables are made with the table() function, just as in theunivariate case. If the two data vectors are x and y, then the command table(x, y) willcreate the table.■ Example 3.1: Is past per<strong>for</strong>mance an indicator of future per<strong>for</strong>mance?A common belief is that an A student in one class will be an A student in the next. Isthis so? The data set grades (<strong>Using</strong>R) contains the grades students received in a mathclass and their grades in a previous math class.> library (<strong>Using</strong>R) # once per session> gradesprev grade1 B+ B+2 A− A−3 B+ A−…

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!