Trend of a few time points Suppose we are given a matrix of many rows (different genes for example) and few columns (different time points) and we want to identify the top rows (genes) that are following a trend, like monotonically increasing or decreasing. What is a good method to perform this in R?
The answers providing also a statistical significance result (something like p-value) are more than welcome. Finally the methods to indicate more complicated cases - such as up-then-down treands - are really perfect.
 A: You didn't mention the type of data you are identifying (continuous, discrete?), but, a simple method to approach this would be to re-code the data into binary values and sum
each row to get the cumulative sum of the magnitude of steps -- the result is your trend strength. Once you have the run data, you can easily rank sort it and bin into percentiles of top and bottom trends per your cutoff thresholds (can use scale and qnorm and set to desired p-values accordingly if desired).
 rnd2bin<-function(x) ifelse(x>=0,1,-1)
 nmat<-matrix(rnorm(1000),100,10)

 bin_ser<-rnd2bin(nmat)
 run<-apply(bin_ser,1,sum)

 # find bottom and top 10% trends
 cut<-quantile(run,c(.1,.9))
 bottomtrend<-which(run < cut[1])
 toptrend<-which(run > cut[2])

> # display top and bottom 10% trend indices


cut

10% 90% 
-4   4 

toptrend

[1]  2 13 19 21 24 28 43 84

bottomtrend

[1] 12 22 38 62 76
*The above code assumes all columns are populated, but possibly (depending on your data) an approach would be to just set any empty columns to zero assuming time intervals are all aligned (this obviously, may not be the best, but it depends on the nature of the data). Without seeing the data, I can't point out a best method, but if they had no time alignment, then one could argue the shorter series with all ones is just as trending as the longer series with all ones.  Some type of calibration needs to be applied in that case.
** as mentioned above, you can set threshold to p-values by scale and qnorm.
e.g. 
z<-as.numeric(scale(run))
pcut<-qnorm(c(.025,.975))
pbottomtrend<-which(z < pcut[1])
ptoptrend<-which(z > pcut[2])

