[R] subsetting question

Dieter Anseeuw dieter.anseeuw at inagro.be
Wed May 20 12:03:28 CEST 2015


Dear all,
I would like to do multiple actions on a subset of my data. Therefore, I want to create a for loop on the variable "Date" (actually a double for loop on yet another variable, but let's omit that for a moment).
I want to run down every level of "Date" and perform multiple actions on the data from a certain date. Here is my code:

for (i in 1:length(datums)){
meanweight<-mean(dataset1[dataset1$Date==datums[i],]$Weight)
...

However, this subsetting obviously doesn't work. How can I adjust my code so that R runs down all levels of Data in a for loop?
(I need the for loop, not tapply(), sapply(), ...)

Thanks in advance,
Dieter Anseeuw

	[[alternative HTML version deleted]]



More information about the R-help mailing list