Blend it all together
With the things you've learned by now, you're able to solve pretty cool problems.
Instead of recording the number of views for your own LinkedIn profile, suppose you conducted a survey inside the company you're working for. You've asked every employee with a LinkedIn profile how many visits their profile has had over the past seven days. You stored the results in a data frame called li_df. This data frame is available in the workspace; type li_df in the console to check it out.
Deze oefening maakt deel uit van de cursus
Intermediate R
Oefeninstructies
- Select the entire second column, named
day2, from theli_dfdata frame as a vector and assign it tosecond. - Use
secondto create a logical vector, that containsTRUEif the corresponding number of views is strictly greater than 25 or strictly lower than 5 andFALSEotherwise. Store this logical vector asextremes. - Use
sum()on theextremesvector to calculate the number ofTRUEs inextremes(i.e. to calculate the number of employees that are either very popular or very low-profile). Simply print this number to the console.
Praktische interactieve oefening
Probeer deze oefening eens door deze voorbeeldcode in te vullen.
# li_df is pre-loaded in your workspace
# Select the second column, named day2, from li_df: second
# Build a logical vector, TRUE if value in second is extreme: extremes
# Count the number of TRUEs in extremes