r-commands - Math 127B Basic R R commands Mrinal Raghupathi...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Math 127B, Basic R, R commands Mrinal Raghupathi This is a list of the commands we use most often in R. The list is not comprehensive, but it covers most of the things we need. 1 Making lists, data frames Basic list creation Make a list and assign it to a name x <- c(1,2,3) Sequence seq(start, stop, step) creates the list of numbers beginning at start, in steps of size step until it reaches stop . > x <- seq(3,15,4) > x [1] 3 7 11 15 Repetition rep(number, times) produces a list with number repeated times times. > x <- rep(5,7) > x [1] 5 5 5 5 5 5 5 Dollar The $ sign can be used to extract a properties. For example the value returned from the lm command, or the column of a data frame. Data frame data.frame() can be used to make a data frame. Supply the names of the columns and the corresponding values with options of the form name = value . > men <- c(45, 86, 12) > women <- c(30 ,105 ,21) > both <- data.frame(gents = men , ladies = women) > both gents ladies 1 45 30 2 86 105 3 12 21 > both$ladies [1] 30 105 21 You can assign a list as a new column of the data frame by using the $ operation and assigning the list to it. 1 2 Statistics Frequency tables table(x) produces the frequencies for entries in x . > grades <- c(’a’, ’b’, ’a’, ’b’,’a’,’a’,’a’,’a’,’b’) > length(grades) [1] 9 > table(grades) x a b 6 3 Using two lists you can get the cross tabulation. For example here are the subject areas in which the grades were recieved. > subjects <- c(’math ’, ’math ’, ’physics ’, ’physics ’ ,’math ’, ’math ’, ’physics ’, ’physics ’, ’math ’) > table(subjects) subjects math physics 5 4 > table(grades , subject) subject grades math physics a 3 3...
View Full Document

This document was uploaded on 10/29/2011 for the course MATH 127B at Vanderbilt.

Page1 / 6

r-commands - Math 127B Basic R R commands Mrinal Raghupathi...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online