1. Number of positive entries in a list. We will write a function that counts the number of positive entries in a given numeric list (of course you can use a simple R statement sum(x>0) to do it).
nPositives<-function(x)
{
n<-length(x);
cnts<-0;
for(i in 1:n)
{
if(x[i]>0) cnts<-cnts+1;
}
return(cnts);
}
To test this function, an example session goes as follows:
>x<-c(1,-3,5,7,0,2,10,-30,50.1,9.9);
>nPositives(x)