Re: [R] identifying when one element of a row has a positive number

2011-01-28 Thread Daisy Englert Duursma
Hello, Thanks to everyone for the multiple answers. Josh, thanks for the function. My data 12 datasets have over 500,000 rows so your answer greatly appreciated. Cheers, Daisy On Thu, Jan 27, 2011 at 9:10 PM, Joshua Wiley jwiley.ps...@gmail.com wrote: Hi, This problem seemed deceptively

Re: [R] identifying when one element of a row has a positive number

2011-01-27 Thread Dennis Murphy
Hi: Try this: f - function(x) ifelse(sum(x 0) == 1L, names(which(x 0)), NA) g - function(x) ifelse(sum(x 0) == 2L, names(which(x == 0L)), NA) apply(df1[, 3:5], 1, f) [1] ANN CTA GLM NAANN NANANANACTA apply(df1[, 3:5], 1, g) [1] NANANANANANAGLM

Re: [R] identifying when one element of a row has a positive number

2011-01-27 Thread Joshua Wiley
Hi, This problem seemed deceptively simple to me. After chasing a considerable number of dead ends, I came up with fg(). It lacks the elegance of Dennis' solution, but (particularly for large datasets), it is substantially faster. I still feel like I'm missing something, but

[R] identifying when one element of a row has a positive number

2011-01-26 Thread Daisy Englert Duursma
Hello, I am not sure where to begin with this problem or what to search for in r-help. I just don't know what to call this. If I have 5 columns, the first 2 are the x,y, locations and the last three are variables about those locations. x-seq(1860,1950,by=10) y-seq(-290,-200,by=10)

Re: [R] identifying when one element of a row has a positive number

2011-01-26 Thread Peter Langfelder
Here's a solution., maybe not the most elegant but works. df.r = df1[, c(3:5)]; # restricted data nNonZero = apply(df.r!=0, 1, sum); one = nNonZero==1; oneZero = nNonZero==2; whichOne = apply(df.r[one, ]!=0, 1, which); whichZero = apply(df.r[oneZero, ]==0, 1, which); colNames = colnames(df.r);