Читать книгу The Big R-Book - Philippe J. S. De Brouwer - Страница 97

4.3.8 Data Frames 4.3.8.1 Introduction to Data Frames

Оглавление

Data frames are the prototype of all two-dimensional data (also known as “rectangular data”). For statistical analysis this is obviously an important data-type.

data frame

rectangular data

Data frames are very useful for statistical modelling; they are objects that contain data in a tabular way. Unlike a matrix in data frame each column can contain different types of data. For example, the first column can be factorial, the second logical, and the third numerical. It is a composite data type consisting of a list of vectors of equal length.

Data frames are created using the data.frame() function.

data.frame()

# Create the data frame. data_test <- data.frame( Name = c(“Piotr”, “Pawel”,“Paula”,“Lisa”,“Laura”), Gender = c(“Male”, “Male”,“Female”, “Female”,“Female”), Score = c(78,88,92,89,84), Age = c(42,38,26,30,35) ) print(data_test) ## Name Gender Score Age ## 1 Piotr Male 78 42 ## 2 Pawel Male 88 38 ## 3 Paula Female 92 26 ## 4 Lisa Female 89 30 ## 5 Laura Female 84 35 # The standard plot function on a data-frame (Figure 4.3) # with the pairs() function: plot(data_test)

pairs()


Figure 4.3: The standard plot for a data frame in R shows each column printed in function of each other. This is useful to see correlations or how generally the data is structured.

The Big R-Book

Подняться наверх