Displaying 4 results from an estimated 4 matches for "first_month".
2016 Oct 27
4
Encontrar la primera columna no NA
...atriz que propusó luisfo en su momento:
> t <- Sys.time()
> M=as.matrix(dat)
> index <- which(!is.na(M)) - 1
> meses<-colnames(M)
> M2<- data.table(columna=index %/% nrow(M) +1L, jugador=index %% nrow(M) +1L , valor=M[index+1L])
> setkey(M2,jugador,columna)
> M2[,.(First_month=meses[columna[1]],Value_First_month=valor[1]),by=jugador]
        jugador First_month Value_First_month
     1:       1         Uno        0.93520715
     2:       2         Uno        0.85930634
     3:       3         dos        0.13521503
     4:       4         Uno        0.86996341
     5:...
2016 Oct 27
2
Encontrar la primera columna no NA
Otra solución algo más rapida:
> t <- Sys.time()
> dat[,jugador:=1:.N]
> dat2=melt(dat,id.vars="jugador")
> setkey(dat2,jugador)
> dat2[,index:=min(which(!is.na(value))),by=jugador]
> dat2[,.(First_month=variable[index[1]],Value_First_month=value[index[1]]),by=jugador]
        jugador First_month Value_First_month
     1:       1         Uno        0.93520715
     2:       2         Uno        0.85930634
     3:       3         dos        0.13521503
     4:       4         Uno        0.86996341...
2016 Oct 27
3
Encontrar la primera columna no NA
...cuatro = sample( c(runif(numero) , rep(NA , numero /1e2 )) ,
size = numero ) ,
            cinco  = sample( c(runif(numero) , rep(NA , numero /2e2 )) ,
size = numero ) ,
            seis   = sample( c(runif(numero) , rep(NA , numero /1e3 )) ,
size = numero )
            )
t <- Sys.time()
First_month <-
  dat %>%
  apply( MARGIN = 1, FUN =
           function(x){
             which( !is.na(x)  ) %>%  min( na.rm = TRUE ) %>%  return()
           }
  )
First_month %>%  table %>%  prop.table
dat[ , First_month := First_month]
N_for <- length( unique(First_month ))
for( j in...
2016 Oct 28
2
Encontrar la primera columna no NA
...,
        cuatro = sample( c(runif(numero) , rep(NA , numero /1e2
        )) , size = numero ) ,
        cinco  = sample( c(runif(numero) , rep(NA , numero /2e2
        )) , size = numero ) ,
        seis   = sample( c(runif(numero) , rep(NA , numero /1e3
        )) , size = numero )
        )
    First_month <-
      apply(X = dat,  MARGIN = 1, FUN =
              function(x){
                return(   min(  which( !is.na(x)  ),  na.rm = TRUE ) )
              }
      )
      dat[ , First_month := First_month]
      N_for <- length( unique(First_month ))
      for( j in 1:N_for){
        x <-...