8.6 Use summarize for quick computation on tbl - Video Tutorials & Practice Problems
Video duration:
1m
Play a video:
Video transcript
<v Voiceover>Dplyr's Summarize</v> function provides access to individual columns of a dataframe or TBL to functions that expect to get a vector. The functions that are used inside Summerize are expected to return only one row or one element. For instance, mean is the perfect example. We wanna calculate the mean of price. We could go ahead and say mean of diamonds, dollars and price, or we could use the Summarize function. We say dia pipe summarize, and as this is Hadley Wickham, we could use both the British spelling and the American spelling. And we say mean of price. Now, that might seem like it took more work to type this than using the straight mean. It will make more sense once we start doing group-by operations. While this column has an unattractive name, we could give it a better name while calling Summarize. We can say dia pipe summarize AvgPrice equals mean of price. The nice thing about Summarize is that it provides functions that turn a single element direct access to individual columns. This will be very handy later on.