Hello everyone I am fairly new to r programming and i was wondering if someone could help me out. I was just playing with r and wanted to make a function that returned a vector of the means of each column in a data set that the user would put in as an argument. The problem is I am trying to do it without the mean r the apply functions so I am just manually trying it out and feel I am very close to finishing it. Just wanted to ask if someone could check it to see where I made an error. Here is my code:
findMeans<- function(data)
{
meanVec <- numeric()
for(i in 1:6)
{
mean=0
for( j in 1:153)
{
value=0
count=0
if(is.na(data[j,i])==FALSE)
{
value= value + data[i,j]
count=count+1
}
else
{
value= value +0
}
}
mean =value/count
meanVec[i]<-mean
}
meanVec
}
and when I try to list the vector it just gives this
> meanVec
numeric(0)
could anyone possibly shed some light on what I am doing wrong?