Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,79 @@ 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)) %>%
clean_names() %>%
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)
Expand Down