Re: [R] Trouble retrieving the second largest value from each row of a data.frame

2010-07-24 Thread David Winsemius
if,else statements to produce these bearing, ifelse is the correct construct for processing vectors -- David. but all I am producing is errors. Any suggestion would be appreciated. Again THANKS for you efforts. Mike Original message Date: Fri, 23 Jul 2010 23:01:56 -0700 From

Re: [R] Trouble retrieving the second largest value from each row of a data.frame

2010-07-24 Thread David Winsemius
preciated. Again THANKS for you efforts. Mike ---- Original message Date: Fri, 23 Jul 2010 23:01:56 -0700 From: Joshua Wiley Subject: Re: [R] Trouble retrieving the second largest value from each row of a data.frame To: mpw...@illinois.edu Cc: r-help@r-project.org Hi, Here is a

Re: [R] Trouble retrieving the second largest value from each row of a data.frame

2010-07-24 Thread Joshua Wiley
value300) or the results should be NA. > > After setting finalbearing with A, B, and C then: > yourdata$finalbearing <- with(yourdata, ifelse ( >                                change.ind <5 & change.ind > 1 , >                                             NA, finalbearing)

Re: [R] Trouble retrieving the second largest value from each row of a data.frame

2010-07-24 Thread David Winsemius
t all I am producing is errors. Any suggestion would be appreciated. Again THANKS for you efforts. Mike Original message Date: Fri, 23 Jul 2010 23:01:56 -0700 From: Joshua Wiley Subject: Re: [R] Trouble retrieving the second largest value from each row of a data.frame To: mpw...@illin

Re: [R] Trouble retrieving the second largest value from each row of a data.frame

2010-07-24 Thread mpward
estion would be appreciated. Again THANKS for you efforts. Mike Original message >Date: Fri, 23 Jul 2010 23:01:56 -0700 >From: Joshua Wiley >Subject: Re: [R] Trouble retrieving the second largest value from each row of >a data.frame >To: mpw...@illinois.edu >Cc: r-help

Re: [R] Trouble retrieving the second largest value from each row of a data.frame

2010-07-24 Thread David Winsemius
On Jul 23, 2010, at 9:20 PM, wrote: I have a data frame with a couple million lines and want to retrieve the largest and second largest values in each row, along with the label of the column these values are in. For example row 1 strongest=-11072 secondstrongest=-11707 strongestantenna=va

Re: [R] Trouble retrieving the second largest value from each row of a data.frame

2010-07-23 Thread Joshua Wiley
Maybe efficiency is less of an issue than I thought, on 2 million rows, it only took a bit over a minute, and my system only jumped up ~ 600 MB of memory so it wasn't much of a strain there either. > data.test <- matrix( + sample(seq(min(yourdata),max(yourdata)), size = 1000, replace = TRUE),

Re: [R] Trouble retrieving the second largest value from each row of a data.frame

2010-07-23 Thread Joshua Wiley
Hi, Here is a little function that will do what you want and return a nice output: #Function To calculate top two values and return my.finder <- function(mydata) { my.fun <- function(data) { strongest <- which.max(data) secondstrongest <- which.max(data[-strongest]) strongestantenna

Re: [R] Trouble retrieving the second largest value from each row of a data.frame

2010-07-23 Thread jim holtman
try this: > x <- read.table(textConnection(" value0 value60 value120 value180 value240 > value300 + 1 -13007 -11707 -11072 -12471 -12838 -13357 + 2 -12838 -13210 -11176 -11799 -13210 -13845 + 3 -12880 -11778 -3 -12439 -13089 -13880 + 4 -12805 -11653 -11071

[R] Trouble retrieving the second largest value from each row of a data.frame

2010-07-23 Thread mpward
I have a data frame with a couple million lines and want to retrieve the largest and second largest values in each row, along with the label of the column these values are in. For example row 1 strongest=-11072 secondstrongest=-11707 strongestantenna=value120 secondstrongantenna=value60 Below