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.

Multivariate data 137[1,] 1 3 5 7[2,] 2 4 6 8> as.data.frame(x) # turn matrix to data frameV1 V2 V3 V41 1 3 5 72 2 4 6 8Coercing a data frame or list into a vector To coerce a list or data frame into a vector,we should start out with all the same type of data, otherwise the data will be coercedimplicitly. The unlist() function, when applied to a list, will <strong>for</strong>m a vector of all the“atomic” components of the list, recursively traversing through a list to do so. Whenapplied to a data frame it goes column by column creating a vector. For example:> x = 1:8;dim(x) = c(2,4);df = data.frame(x)> dfX1 X2 X3 X41 1 3 5 72 2 4 6 8> unlist(df)X11 X12 X21 X22 X31 X32 X41 X421 2 3 4 5 6 7 8

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

Saved successfully!

Ooh no, something went wrong!