To undertsand how a functions can be interlinked ##set working directory## setwd(“F:/R-BA/scripts/data”)
df <- read.csv(“activity.csv”, header=T, stringsAsFactors=F) View(df)
df1count <- sum(is.na(df$steps)) df1count View(df1count)
library(dplyr) df1<- subset(df, steps !=“NA”) df1 <- summarise(group_by(df1, interval), steps=mean(steps))
replace_na <- function(step, interval) { ifelse(is.na(step), df1[df1$interval == interval, ]$steps, step) }
dfnew <- df dfnew\(steps <- mapply(replace_na, dfnew\)steps, dfnew$interval) head(dfnew)
df2count <-sum(is.na(dfnew$steps)) df2count View(df2count)
The file contained 17569 values which had 2304 NA’s after filtering the data in R using the code two data frames were created which had one data frame which had only 2304 NA’s In the original df file means were given of some values and hence using group by I found the means of all the NA values .Later by using Replace I substituted all the values of NA’S and hence created a new data frame which had all the mean values of NA’s