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

Naming Rows and Columns

Оглавление

In the preceding code, we have named columns when we created the data-frame. It is also possible to do that later or to change column names …and it is even possible to name each row individually.

# Get the rownames. colnames(data_test) ## [1] “Name” “Gender” “Score” “Age” “End_date” rownames(data_test) ## [1] “1” “2” “3” “4” “5” colnames(data_test)[2] ## [1] “Gender” rownames(data_test)[3] ## [1] “3” # assign new names colnames(data_test)[1] <- “first_name” rownames(data_test) <- LETTERS[1:nrow(data_test)] print(data_test) ## first_name Gender Score Age End_date ## A Piotr Male 80 42 2014-03-01 ## B Pawel Male 88 38 2017-02-13 ## C <NA> Female 92 26 2014-10-10 ## D Lisa Female 89 30 2015-05-10 ## E Laura Female 84 35 2010-08-25

The Big R-Book

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