keeping original and new variables in df

I am trying to mean-center multiple variables at the same time. I am using the code below, which is replacing the original variables with the mean-centered variables. I want to keep BOTH the original variables and mean-centered variables. Does anyone know how I could modify my code to do that? vars_to_mc <- c("interview_age_1_year", "pea_wiscv_tss_baseline", "cbcl_scr_dsm5_adhd_r_baseline",… Read More keeping original and new variables in df

Select quarterly months values

From the given dataframe i am trying to extract quarterly_values however it fails when i try to mutatue every third month values . mont_dates <- c("201401", "201402", "201403", "201404", "201405", "201406", "201407", "201408", "201409", "201410", "201411", "201412") cat <- c("new", "old", "undefined", "new", "old", "undefined", "undefined", "new", "old", "undefined", "new", "old") mont_vals <- c(221, 433,… Read More Select quarterly months values

Using mutate to get an average of the previous weeks temperature

I’m looking for a way to create a new variable for an average of the temperature the week before. I’ve got a data frame that looks like the following weather_data Rows: 3,664 Columns: 2 $ dt <date> 2014-01-01, 2014-01-02, 2014-01-03, 2014-01-04, 2014-01… $ temp <dbl> 6.390000, 6.234167, 6.307500, 4.436250, 4.432917, 8.4508… What I’m hoping to… Read More Using mutate to get an average of the previous weeks temperature