I am new to R, I have a question about Loop through all the combinations of unique days and unique individuals in the activity_budget dataset. For each iteration of the inner loop subset on the current value of day and individual of your loops. Calculate the mean time value for this subset and store it in a vector called my_vector . I write a bunch of code but I received an error. thank you in advanced.
setwd("C:/ /")
activity_budget <- read.csv("activity_budget.csv")
getwd()
str(activity_budget)
head(activity_budget)
my_vector<-NULL
for(i in unique(activity_budget$day)){
for(j in unique(activity_budget$individual)){
subset_data<-subset(activity_budget, activity_budget$day == i & activity_budget$individual== j)
my_vector<-mean(activity_budget$time[subset(activity_budget, activity_budget$day & activity_budget$individual)],na.rm=TRUE)
}
}