Re: [R] Selecting maximums between different variables

2013-10-17 Thread Law, Jason
ginal Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Tim Umbach Sent: Thursday, October 17, 2013 9:49 AM To: r-help@r-project.org Subject: [R] Selecting maximums between different variables Hi there, another beginners question, I'm afraid. B

Re: [R] Selecting maximums between different variables

2013-10-17 Thread arun
Hi, You could also check ?data.table() as it could be faster. #Speed comparison set.seed(498) oilT <- data.frame(YEAR=rep(rep(1800:2012,50),100),state=rep(rep(state.abb,each=213),100),value=sample(2000:8,1065000,replace=TRUE),stringsAsFactors=FALSE) system.time(res1 <- oilT[as.logical(wi

Re: [R] Selecting maximums between different variables

2013-10-17 Thread Berend Hasselman
On 17-10-2013, at 18:48, Tim Umbach wrote: > Hi there, > > another beginners question, I'm afraid. Basically i want to selct the > maximum of values, that correspond to different variables. I have a table > of oil production that looks somewhat like this: > > oil <- data.frame( YEAR = c(2011,

Re: [R] Selecting maximums between different variables

2013-10-17 Thread arun
Hi, You may try: unlist(lapply(seq_len(nrow(oil)),function(i) oil[i,-1][which.max(oil[i,-1])]))  #  CA    ND #4 6  #or library(reshape2) datM <- melt(oil,id.var="YEAR") datM[as.logical(with(datM,ave(value,list(YEAR),FUN= function(x) x%in% max(x,] #  YEAR variable value #3 2011  

[R] Selecting maximums between different variables

2013-10-17 Thread Tim Umbach
Hi there, another beginners question, I'm afraid. Basically i want to selct the maximum of values, that correspond to different variables. I have a table of oil production that looks somewhat like this: oil <- data.frame( YEAR = c(2011, 2012), TX = c(2, 3),