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

Adding Rows to a Data-frame

Оглавление

Adding rows corresponds to adding observations. This is done via the function rbind().

rbind()

# To add a row, we need the rbind() function: data_test.to.add <- data.frame( Name = c(“Ricardo”, “Anna”), Gender = c(“Male”, “Female”), Score = c(66,80), Age = c(70,36), End_date = as.Date(c(“2016-05-05”,“2016-07-07”)) ) data_test.new <- rbind(data_test,data_test.to.add) print(data_test.new) ## Name Gender Score Age End_date ## 1 Piotr Male 80 42 2014-03-01 ## 2 Pawel Male 88 38 2017-02-13 ## 3 <NA> Female 92 26 2014-10-10 ## 4 Lisa Female 89 30 2015-05-10 ## 5 Laura Female 84 35 2010-08-25 ## 6 Ricardo Male 66 70 2016-05-05 ## 7 Anna Female 80 36 2016-07-07

The Big R-Book

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