Thank you very much! That worked like a dream.

Paul

----- Original Message -----

From: "Rui Barradas [via R]" <

[hidden email]>

To: "AppleJax" <

[hidden email]>

Sent: Wednesday, January 4, 2012 4:44:52 PM

Subject: Re: subset function

Hello,

Here are two solutions.

The first creates a logical matrix 'inx1' that you can use with 'subset'

The second creates a list of indices that you can use to directly access the data frame rows you want.

set.seed(1234)

tst <- Sys.time()+1:10

p1 <- runif(10, 30, 50)

p2 <- sample(35:45, 10, T)

dfr <- data.frame(TS=tst, p1=p1, p2=p2)

dfr

inx1 <- apply(dfr[-1], 2, function(x) x >= 40)

inx2 <- apply(dfr[-1], 2, function(x) which(x >= 40))

for(i in 1:ncol(inx1))

print(subset(dfr, subset=inx1[, i], select=c(1, i+1)))

for(i in 1:length(inx2))

print(dfr[inx2[[i]], c(1,i+1)])

I hope this helps

Rui Barradas

If you reply to this email, your message will be added to the discussion below:

http://r.789695.n4.nabble.com/subset-function-tp4263093p4263238.html
To unsubscribe from subset function, click here .

NAML