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.

depending on the number of days of frost they get.Using table to count the number of observationsOne interesting piece of analysis is to count how many states are in eachbracket. You can do this with the table() function, which simply counts the numberof observations in each level of your factor.> x table(x)xLow Med High11 19 20You encounter the table() function again in Chapter 15.Combining and Merging Data SetsNow you have a grasp of how to subset your data and how to performcalculations on it. The next thing you may want to do is combine data fromdifferent sources. Generally speaking, you can combine different sets of data inthree ways:By adding columns: If the two sets of data have an equal set of rows, and theorder of the rows is identical, then adding columns makes sense. Your optionsfor doing this are data.frame or cbind() (see Chapter 7).By adding rows: If both sets of data have the same columns and you want toadd rows to the bottom, use rbind() (see Chapter 7).By combining data with different shapes: The merge() function combinesdata based on common columns, as well as common rows. In databaseslanguage, this is usually called joining data.Figure 13-1 shows these three options schematically.In this section, we look at some of the possibilities of combining data withmerge(). More specifically, you use merge() to find the intersection, as well as theunion, of different data sets. You also look at other ways of working with lookuptables, using the functions match() and %in%.

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

Saved successfully!

Ooh no, something went wrong!