Hi Cecilia,

Trying it your way there where three reasons for errors, I fixed them in the
following code:


means<-matrix(nrow=3,ncol=4)

counter.i <- 0
counter.j <- 0

for (i in levels(factor(data$industry)))
{
counter.i <- counter.i + 1
 for (j in levels(factor(data$year)))
{
counter.j <- counter.j + 1
 means[counter.i,counter.j]<- mean(data$X1 [data$industry == i & data$year
== j]  ,na.rm=TRUE)
}
 counter.j <- 0
}

means



Also consider ddply in the plyr package (although that's an over kill if
your only having two loops)

Or Jorge solution.

Cheers,
Tal G





On Sun, Jun 28, 2009 at 7:39 PM, Cecilia Carmo <cecilia.carmo@ua.pt> wrote:

> for ( i in unique(data$industry))
>  for (j in data$year){means[i,j]<-mean(data$X1,na.rm=TRUE)}
>



-- 
----------------------------------------------


My contact information:
Tal Galili
Phone number: 972-50-3373767
FaceBook: Tal Galili
My Blogs:
http://www.r-statistics.com/
http://www.talgalili.com
http://www.biostatistics.co.il

	[[alternative HTML version deleted]]


