{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

5-ListsAndApply

# Con9nued dist cd1 d2 d3 d4 d5 neww dataframex

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

This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: - 67 - 68 - 61 - 60 - 57 - 58 - 56 - 48 - 51 - 68 - 54 [29] - 51 - 48 - 46 - 35 - 67! We subset rows and columns of data frames We subset by posi?on, exclusion, logical, name, and all Reformakng the data frame Revise the Structure w newW Data Frame Data Frame x x y S1 S2 S3 S4 Data Frame ap has ﬁve rows and 2 columns (x, y) with the loca9ons of the ﬁve access points S5 y SS AP Dist x y S1 1 D1 x y S2 2 D2 x y S5 5 D5 X = rep(w\$x, 5) Y = rep(w\$y, 5) AP = rep(1:5, each = nrow(w)) SS = c(w\$S1, w\$S2, w\$S3, w\$S4, w\$S5) D1 = sqrt((w\$x - ap[1, "x"] )^2 + (w\$y - ap[1, "y”])^2 ) D2 = sqrt((w\$x - ap[2, "x"] )^2 + (w\$y - ap[2, "y"])^2 ) D3 = sqrt((w\$x - ap[3, "x"] )^2 + (w\$y - ap[3, "y"])^2 ) D4 = sqrt((w\$x - ap[4, "x"] )^2 + (w\$y - ap[4, "y"])^2 ) D5 = sqrt((w\$x - ap[5, "x"] )^2 + (w\$y - ap[5, "y"])^2 )! Con9nued.. Dist = c(D1, D2, D3, D4, D5)! newW = data.frame(x = X, y = Y, ! AP, SS, Dist)! Lists Review •  Data frames are actually a special kind of list. •  Unlike a data frame each element in a list can have a diﬀerent length. •  Actually, each element can be either a list, data frame, vector, matrix, … List Vector Data frame Matrix Rainfall •  Daily rainfall collected at 5 weather sta9ons •  rain is a list of length 5 –  One element for each sta9on –  Each element is a numeric vector of rain measurements –  Sta9ons not in opera9on for the same length of 9me rain List load(url( “http://www.stanford.edu/~vcs/StatData/ rainfallCO.rda”))   > class(rain) [1] "list"! > length(rain) [1] 5! > names(rain) [1] "st050183" "st050263" "st050712" "st050843" "st050945"! ! Indexing lists •  Lists can be indexed by name, using \$. > class(rain\$st050183) [1] "numeric" > length(rain\$st050183) [1] 9878 > head(rain\$st050183) [1] 0 10 11 1...
View Full Document

{[ snackBarMessage ]}

Ask a homework question - tutors are online