I am currently working on a climate data set and have two main questions that I haven't been able to resolve.
Data = https://ufile.io/u2dszh4x
Is there a way to melt the season field before its corresponding column so that it yields something like this https://i.stack.imgur.com/MMcYH.jpg I would like to generate a new class in the season column named "grow" which contains the sum of ppt and the mean for every other parameter for the spring and summer months. I originally tried to have prism_grouped with a column for the year and each other column and individual observation i.e(spring_ppt_mm,summer_ppt_mm,fall_ppt_mm,winter_ppt_mm, ...) and calculating it from there using mutate but melting and gathering the data always gave me wonky results.
When trying to calculate the z score for each season I get NaN filled on the output database when I use this approach:
spring <- prism_grouped %>%
filter(season == "spring") %>%
mutate(z_ppt_mm = scale(ppt_mm)) %>%
mutate(z_tmin_c = scale(tmin_c)) %>%
mutate(z_tmean_c = scale(tmean_c)) %>%
mutate(z_tmax_c = scale(tmax_c)) %>%
mutate(z_vdpmin_hpa = scale(vdpmin_hpa)) %>%
mutate(z_vdpmax_hpa = scale(vdpmax_hpa))
but get a valid result if I do the following:
spring <- filter(prism_grouped,season == "spring")
z_spr_ppt <- scale(spring$ppt_mm)
z_spr_tmin <- scale(spring$tmin_c)
z_spr_tmean <- scale(spring$tmean_c)
z_spr_tmax <- scale(spring$tmax_c)
z_spr_vdpmin <- scale(spring$vdpmin_hpa)
z_spr_vdpmax <- scale(spring$vdpmax_hpa)
I currently have everything working with the second method but I am trying to reduce the number of variables I am working with and would prefer to contain them in data frames. Any suggestions would be appreciated!