Hi,

I have a data frame with 15 different years and each year has a different
sample size.  I'm having trouble writing a for loop to have a t-test done
for each year for two of the columns.  Thus far I have been able to loop
over the years but the output is the same t-test 15 times.  I'm new to
writing loops and functions, and am trying to figure out a way to use them
together (if there are any general rules to follow, I would be great-full
to know)

for(year in 1998:2012){
  b <-t.test(tr$adj_ind_pop_dif, tr$ind_nei_dif, paired=TRUE)
  print(b)
}

the other way I did it was to take subsets of the dataframe and then do a
separate t-test for each
ab<-subset(tr, BroedJaar =="1999")
t.test(ab$ind_nei_dif, ab$adj_ind_pop_dif, paired=TRUE)

Best,

Monaly.

	[[alternative HTML version deleted]]


