0 votes
in R Language by
Basic function in R language

1 Answer

0 votes
by

In the previous example, you didn't store the summary statistic in a data frame.

You can proceed in two steps to generate a date frame from a summary:

  • Step 1: Store the data frame for further use
  • Step 2: Use the dataset to create a line plot

Step 1) You compute the average number of games played by year.

## Mean
ex1 <- data % > %
	group_by(yearID) % > %
	summarise(mean_game_year = mean(G))
head(ex1)

Code Explanation

  • The summary statistic of batting dataset is stored in the data frame ex1.
  • Step 2) You show the summary statistic with a line plot and see the trend.

    # Plot the graph
    ggplot(ex1, aes(x = yearID, y = mean_game_year)) +
        geom_line() +
        theme_classic() +
        labs(
            x = "Year",
            y = "Average games played",
            title = paste(
                "Average games played from 1871 to 2016"
            )
        )

Related questions

0 votes
asked Nov 13, 2019 in R Language by MBarbieri
0 votes
asked Nov 14, 2019 in R Language by MBarbieri
...