Selecting variables in most statistics packages is very simple. For example, SAS uses VAR Q1-Q4 to select variables q1, q2, q3 and q4. Selecting observations on the other hand usually uses logic like GENDER="F" to select all the females. That logic is used in various commands like WHERE, IF, and so on. R is radically different in that it allows you to use many of the same methods to select both variables and observations. For example you could use logic to select all your numeric variables and row names (like variable names except for observations) to select observations. This perspective offers such great flexibility that our books include three chapters of variations. That requires too much discussion for this web site, so I'll present just some basic examples. However, these exam do cover many of the most common selection tasks. The example programs below select the males and variables workshop and q1 through q4 and save them to a new data set called myMalesWQ. The R program actually lists the print() function even though that is the default. This is to show how the selection would look inside other function calls. The R and Stata programs demonstrate this selection several different ways. The SAS and SPSS programs focus on the main way you would this in those packages. As with all examples, these program files and the data files they use are available here. The programs and the data they use are also available for download here. Detailed step-by-step explanations are in the books, but if you read the comments and/or run the programs, it is fairly obvious what the packages are doing.
|