Exercise

# Summarizing variables with rxSummary()

Let's summarize some data using the **rxSummary()** and **rxCrossTabs()** functions.

Instructions

**100 XP**

Use **rxSummary()** to summarize the variables corresponding to the day of the week, the closing price, and the volume traded.

The simple syntax is:
**rxSummary(formula, data)**

**formula**- A formula containing the variables that you want to summarize. Typically this formula only has variables on the right side of the**~**. In this example, we will separate different variables with a**+**.**data**- The dataset in which you want to look for variables specified in**formula**.

Go ahead and use **rxSummary()** to summarize the variables corresponding to the day of the week, the closing price, and the volume traded.

If we wanted to weight each observation differently, then we can use either the **pweights** or the **fweights** argument. **pweights** correspond to probability weights, while **fweights** correspond to frequency weights.

Go ahead and summarize the variables corresponding to the day of the week and closing price again. This time, use the **fweights** argument to use the volume traded as a frequency weight.

You should notice that the frequency counts for the day of the week variable are substantially higher.

You can also compute cross tabulations and frequency counts by using the **rxCrossTabs()** function.

The simple syntax of **rxCrossTabs()** is very similar to **rxSummary()**:

**rxCrossTabs(formula, data)**

**formula**- A formula containing the variables that you want to cross tabulate. This formula operates very similarly to the formula provided to the open-source function**xtabs()**.**data**- The dataset in which you want to look for variables specified in**formula**.

Go ahead and use **rxCrossTabs()** to compute the frequencies for each level in the variable corresponding to the day of the week. The use of frequency and probability weights are also available in this function via the **fweights** and **pweights** arguments, respectively.