November 2018
Beginner to intermediate
354 pages
6h 59m
English
Now, suppose instead of prices for 2018 only, we have prices for these items for 2017, 2016, and 2015 as well. This new data frame is defined as follows:
all_prices = data.frame(items = rep(c("potato", "rice", "oil"), 4), jan_price = c(10, 20, 30, 10, 18, 25, 9, 17, 24, 9, 19,27), mar_price = c(11, 22, 33, 13, 25, 32, 12, 21, 33, 15, 27,39), june_price = c(20, 25, 33, 21, 24, 40, 17, 22, 27, 13, 18,23) )all_prices
The output for the preceding lines of code can be seen as follows:

Now suppose we want to take the mean price of different items for very March in all years. We can do this by using tapply(numerical_variable, categorical_variable, ...
Read now
Unlock full access