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
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
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,
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
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),
5 matches
Mail list logo