From e96837309c721630d08d2f2ee8196a6275e29809 Mon Sep 17 00:00:00 2001 From: Vinita Date: Tue, 25 May 2021 16:22:12 -0700 Subject: [PATCH] peer review Vinita --- .../index.Rmd | 66 +++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/content/post/2021-04-16-functional-programming-with-strava-data/index.Rmd b/content/post/2021-04-16-functional-programming-with-strava-data/index.Rmd index a7533c6..5f02d16 100644 --- a/content/post/2021-04-16-functional-programming-with-strava-data/index.Rmd +++ b/content/post/2021-04-16-functional-programming-with-strava-data/index.Rmd @@ -57,6 +57,7 @@ There are many variations of passages of Lorem Ipsum available, but the majority #reading in data for sandbox strav_data <- read_csv(here("content/post/2021-04-16-functional-programming-with-strava-data/data", "strav_csv.csv")) +<<<<<<< Updated upstream #starting with some initial tidying dataready <- strav_data %>% select(where(~length(unique(.)) > 1)) %>% @@ -64,6 +65,71 @@ dataready <- strav_data %>% mutate_if(is.numeric, ~round(., 2)) +======= +#------Vinita------# + +#Recommend using rio for importing data +library(rio) +library(janitor) +strav_data = import(here("content/post/2021-04-16-functional-programming-with-strava-data/data", "strav_csv.csv"),setclass = "tibble") %>% + characterize() %>% + clean_names() +#------Vinita------# + + +#initial function for tidying Stravadata +tidyfunc <- function(strav_data) { +strav_data %>% + select(where(~length(unique(.)) > 1)) %>% + clean_names() %>% + mutate_if(is.numeric, ~round(., 2)) %>% + filter(type != "Swim") %>% + mutate(type = as.factor(type)) %>% + separate(start_date_local, c("date","time"), sep = " ") %>% + select(-start_date) +} + +#Vinita - very cool use of a funtion here. + +#Function taken directly from Lab3 to determine percentage of each activity in dataset +# Using proportions could be useful to select only the most common activities (e.g., >5%) +proportions_activity <- function(activities) { + map_dbl(split(activities, activities), length) / length(activities) +} + + + +#------Vinita------# +#This is very cool stuff. As a reader, it will be helpful if you add comments as to what's happening at every step + +#I am going to try parsing out the following function and please ignore me if I am wrong + +tidyfunc <- function(strav_data) { +strav_data %>% + #select only those columns which do not have columns with just one unique value - add reason + select(where(~length(unique(.)) > 1)) %>% + #make those col_names easier to read by adding underscores or making them lower case + clean_names() %>% + #round every numeric column - add reason + mutate_if(is.numeric, ~round(., 2)) %>% + #keep all rows except type ="Swim" - add reason + filter(type != "Swim") %>% + #convert to factor + mutate(type = as.factor(type)) %>% + #parse the start_date_local column into date and time cols; check out lubridate::`parse_date_time()` + separate(start_date_local, c("date","time"), sep = " ") %>% + #select all cols except start_date + select(-start_date) +} + + +#------Vinita------# + + +tidy1 <- tidyfunc(strav_data) +a <- proportions_activity(tidy1$type) + +>>>>>>> Stashed changes # uniquecols <- function(x) length(unique([,y]) > 1)