Rows: 39 Columns: 12
── Column specification ────────────────────────────────────────────────────────
Delimiter: ","
dbl (12): X1, X2, X3, X4, X5, X6, X7, X8, X9, X10, X11, X12
ℹ Use `spec()` to retrieve the full column specification for this data.
ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
Data analysis code shuffle (solution)
Exercise
We are interested in understanding the monthly variation in precipitation in Gainesville, FL. We’ll use some data from the NOAA National Climatic Data Center. Each row of the data is a year (from 1961-2013) and each column is a month (January - December).
Rearrange the following program so that it:
- Loads the readr package
- Imports the data from the web into a data frame
- Calculates the mean precipitation (ppt) in each month across years
- Plots the monthly averages as a simple line plot
Finally, add a comment above the code that describes what it does. The comment character in R is #
.
It’s OK if you don’t know exactly how the details of the program work at this point, you just need to figure out the right order of the lines based on when variables are defined and when they are used.
plot(monthly_mean_ppt, type = "l", xlab = "Month", ylab = "Mean Precipitation")
<- colMeans(ppt_data)
monthly_mean_ppt library(readr)
<- read_csv("https://datacarpentry.org/semester-biology/data/gainesville-precip.csv", header = FALSE) ppt_data
Output solution