[R] how to show date with this subset

Alfonso Sammassimo cincinattikid at bigpond.com
Thu Feb 22 16:14:23 CET 2007


Dear List,

Thankyou to Jim and Marc for their help on my previous question.

I have a data frame of five columns, the first being a list of dates and the 
other four columns are numeric values. I wanted to list the days where all 4 
columns of values are less than in the previous row. I used the following 
which works fine, except it doesnt show the dates for each row (the values 
from column 1).

differences <- apply(x, 2, diff)
all.lower.diffs <- subset(differences, apply(differences, 1, 
function(x){all(x<0)}

I tried using the following loop instead, but it would only apply to the 
first column of every row("warning condition has length>1 and only first 
element will be used"):

for ( i in 2:length(x[,1]))  if (x[i,]<x[i-1,]) {print(x[i,])}

How can I resolve with either method? Any help much appreciated.

Regards,
Alf Sammassimo.



More information about the R-help mailing list