Use a function
The documentation on the mean() function gives us quite some information:
- The
mean()function computes the arithmetic mean. - The most general method takes multiple arguments:
xand.... - The
xargument should be a vector containing numeric, logical or time-related information.
Remember that R can match arguments both by position and by name. Can you still remember the difference? You'll find out in this exercise!
Once more, you'll be working with the view counts of your social network profiles for the past 7 days. These are stored in the linkedin and facebook vectors and have already been created for you.
Questo esercizio fa parte del corso
Intermediate R
Istruzioni dell'esercizio
- Calculate the average number of views for both
linkedinandfacebookand assign the result toavg_liandavg_fb, respectively. Experiment with different types of argument matching! - Print out both
avg_liandavg_fb.
Esercizio pratico interattivo
Prova a risolvere questo esercizio completando il codice di esempio.
# The linkedin and facebook vectors have already been created for you
linkedin <- c(16, 9, 13, 5, 2, 17, 14)
facebook <- c(17, 7, 5, 16, 8, 13, 14)
# Calculate average number of views
# Inspect avg_li and avg_fb