I am new to R and StackOverflow. I'm looking for some help with a specific problem.
I have a data set that includes a column for year, age, ID, horn length etc. There are several ID's in each year and each ID is in several years etc.
I want to create a for loop that
- subsets the data into years
- calculates the mean horn length within each year
- prints the mean to the screen
This is what I have so far:
BH_YEAR <- split(Bighorn, as.factor(Bighorn$Year))
for(i in 1:length(BH_YEAR)) {
cat(mean(Bighorn$HornLength, na.rm=TRUE))
}
but it is just prints the mean horn length of the whole data set 24 times.
Any help very much appreciated.