3. Wk2_DataTypesVectorsAndSubsets2013

The result will be coerced to a simpler structure

Info iconThis preview shows page 1. Sign up to view the full content.

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

Unformatted text preview: 7 55 24 46 48 > sort(fage) [1] 24 27 27 33 33 46 47 48 52 55 59 67 77 79 > sort(fage, decreasing = TRUE) [1] 79 77 67 59 55 52 48 47 46 33 33 27 27 24 sort() and order() > fage [1] 77 33 79 47 27 33 67 52 59 27 55 24 46 48 > order(fage) [1] 12 5 10 2 6 13 4 14 8 11 9 7 1 3 No6ce that the return value from order tells us that the 12th element of fage is the smallest, the 5th is the second smallest, ..., and the 3rd is the largest This func6on has a decreasing argument too. Return to our subsets: •  BMI of every other person in the family bmi[ seq(1, 14, by = 2) ] •  Weights of the women in our family fweight[ fgender == “f”] •  Height elements “a”, “c”, “f” veight[ c(“a”, “c”, “f”) ] •  Assign every one in the family the last name of “Smith” > lastname = character(length = 14) > lastname [1] "" "" "" "" "" "" "" "" "" "" "" "" "" "" > lastname = "Smith" > lastname [1] "Smith" "Smith" "Smith" "Smith" "Smith" "Smith" "Smith” [8] "Smith" "Smith" "Smith" "Smith" "Smith" "Smith" "Smith" > lname = character() > lname character(0) > lname[1:14] = "Smith" > lname [1] "Smith" "Smith" "Smith" "Smith" "Smith" "Smith" "Smith" [8] "Smith" "Smith" "Smith" "Smith" "Smith" "Smith" "Smith" Data Frames The Family •  We have all sorts of informa6on about our family, height, weight, first name, gender, … •  The data frame gives us a way to collect all of these variables (vectors) into one object. > data.frame(firstName = fnames, gender = fgender, age = fage, height = veight, weight = fweight, bmi = umi, overWt = foverWt) > family! firstName gender age height weight bmi overWt! 1 Tom m 77 70 175 25.16239 TRUE! 2 May f 33 64 125 21.50106 FALSE! 3 Joe m 79 73 185 24.45884 FALSE! 4 Bob m 47 67 156 24.48414 FALSE! 5 Sue f 27 64 105 18.06089 FALSE! 6 Liz f 33 68 190 28.94981 TRUE! 7 Jon m 67 68 185 28.18797 TRUE! 8 Sal f 52 65 124 20.6...
View Full Document

Ask a homework question - tutors are online