I want to generate a vector of means derived from subsets of an existing vector in R.
My data look like this:
date plant_ID treatment stalk_count flower_count
195 1 control 0 0
196 1 control 0 0
197 1 control 0 0
198 1 control 0 0
.........................................................
237 98 treatment 0 0
239 98 treatment 0 0
226 98 treatment 2 9
I think I need to use split() to break the data into subsets by plant_ID, but do not know how to tell lapply() to take these subsets, and apply the mean() function to the flower_count data contained within each subset.
My questions are: 1- Is this an approach that will work? 2- How would I write the code to do this?