12.07.2015 Views

R dummies

R dummies

R dummies

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

As explained in the “Combining vectors into a matrix” section, rbind() can takemultiple arguments, as long as they’re compatible. In this case, you bind a vectorc(7,4) at the bottom of the data frame.Note that R, by default, sets the row number as the row name for the addedrows. You can use the rownames() function to adjust this, or you can do thatimmediately by specifying the row name between quotes in the rbind()function like this:> baskets.df baskets.dfGranny Geraldine1st 12 52nd 4 43rd 5 24th 6 45th 9 126th 3 97th 7 4Alternatively, you can use indexing as well, to add an extra observation. Yousee how in the next section.Adding a series of new observations using rbindIf you need to add multiple new observations to a data frame, doing it one-byoneis not entirely practical. Luckily, you also can use rbind() to attach a matrix ora data frame with new observations to the original data frame. The matching ofthe columns is done by name, so you need to make sure that the columns in thematrix or the variables in the data frame with new observations match the variablenames in the original data frame.Let’s add another two game results to the data frame baskets.df. First, youconstruct a new data frame with the number of baskets Granny and Geraldinescored, like this:

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

Saved successfully!

Ooh no, something went wrong!