[R] difference

2016-10-27 Thread Ashta
Hi all,

I want to calculate the difference  between successive row values to
the first row value within year.
How do I get that?

 Here isthe sample of data
Year   Num
200125
200175
2001   150
200230
200285
200295

Desired output
Year   Num  diff
200125   0
200175  50
2001  150125
2002300
200285  55
200295  65

Thank you.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] Significance of Svyrepdesign Object Warning

2016-10-27 Thread Courtney Benjamin
​Thank you; I will do so.


Courtney Benjamin

Broome-Tioga BOCES

Automotive Technology II Teacher

Located at Gault Toyota

Doctoral Candidate-Educational Theory & Practice

State University of New York at Binghamton

cbenj...@btboces.org

607-763-8633


From: William Dunlap 
Sent: Thursday, October 27, 2016 9:59 PM
To: Courtney Benjamin
Cc: Anthony Damico; r-help@r-project.org; Thomas Lumley
Subject: Re: [R] Significance of Svyrepdesign Object Warning

For, now I would just use na.action=na.omit instead of na.exclude.  My comments 
were mainly for the package author.

Bill Dunlap
TIBCO Software
wdunlap tibco.com

On Thu, Oct 27, 2016 at 5:53 PM, Courtney Benjamin 
> wrote:

Hello Mr. Dunlap,

I have gone back and re-read the responses to my question.  I am interested in 
trying to apply your recommendation so I am doing things correctly; however I 
am not sure how to go about doing it within my code.  It appears that you are 
digging quite deeply into R where I am not yet familiar.  I am including a 
reproducible example; would you be willing to show an example of how it would 
be done?  I greatly appreciate your advisement and time.

Sincerely,

Courtney


library(RCurl)
library(survey)
data <- 
getURL("https://raw.githubusercontent.com/cbenjamin1821/careertech-ed/master/elsq1adj.csv;)
elsq1ch <- read.csv(text = data)
#Specifying the svyrepdesign object which applies the BRR weights
elsq1ch_brr<-svrepdesign(variables = elsq1ch[,1:16], repweights = 
elsq1ch[,18:217], weights = elsq1ch[,17], combined.weights = TRUE, type = "BRR")
elsq1ch_brr
#Logistic regression call which yields a warning regarding svyrepdesign object
allCC 
<-svyglm(formula=F3ATTAINB~F1PARED+BYINCOME+F1RACE+F1SEX+F1RGPP2+F1HIMATH+F1RTRCC,family="binomial",design=elsq1ch_brr,subset=BYSCTRL==1==1,na.action=na.exclude)
summary(allCC)


​


Courtney Benjamin

Broome-Tioga BOCES

Automotive Technology II Teacher

Located at Gault Toyota

Doctoral Candidate-Educational Theory & Practice

State University of New York at Binghamton

cbenj...@btboces.org

607-763-8633


From: William Dunlap >
Sent: Sunday, October 23, 2016 2:24 PM
To: Anthony Damico
Cc: Courtney Benjamin; r-help@r-project.org; 
Thomas Lumley
Subject: Re: [R] Significance of Svyrepdesign Object Warning

The immediate problem could be solved by changing the following lines in 
survey:::summary.svrepglm from
presid <- resid(object, "pearson")
dispersion <- sum(object$survey.design$pweights * presid^2,
na.rm = TRUE)/sum(object$survey.design$pweights)
to
presid <- resid(object, "pearson")
pweights <- naresid(object$na.action, object$survey.design$pweights)
dispersion <- sum(pweights * presid^2, na.rm = TRUE)/sum(pweights,
na.rm = TRUE)

'naresid' uses the information from na.exclude to match up the residuals
with the row in the data that they correspond to.  resid() calls it so it should
also be applied to pweights so they line up correctly.




Bill Dunlap
TIBCO Software
wdunlap tibco.com

On Sun, Oct 23, 2016 at 11:17 AM, Anthony Damico 
> wrote:
hi, great example.  i am ccing survey package author/maintainer dr.
lumley.  why do you have `na.action=na.exclude`?  if you remove it, things
work as expected--


library(RCurl)
library(survey)
data <- getURL("
https://raw.githubusercontent.com/cbenjamin1821/careertech-ed/master/elsq1adj.csv
")
elsq1ch <- read.csv(text = data)
#Specifying the svyrepdesign object which applies the BRR weights
elsq1ch_brr<-svrepdesign(variables = elsq1ch[,1:16], repweights =
elsq1ch[,18:217], weights = elsq1ch[,17], combined.weights = TRUE, type =
"BRR")
elsq1ch_brr
#Logistic regression call which yields a warning regarding svyrepdesign
object

# your warning
a <-
svyglm(formula=F3ATTAINB~F1PARED+BYINCOME+F1RACE+F1SEX+F1RGPP2+F1HIMATH+F1RTRCC,family="binomial",design=elsq1ch_brr,subset=BYSCTRL==1==1,na.action=na.exclude)
summary(a)

# works fine
a <-
svyglm(formula=F3ATTAINB~F1PARED+BYINCOME+F1RACE+F1SEX+F1RGPP2+F1HIMATH+F1RTRCC,family="binomial",design=elsq1ch_brr,subset=BYSCTRL==1==1)
summary(a)



the mismatch of vectors generating that warning happens inside

debug(survey:::summary.svrepglm)

[..snip..]

Browse[2]> length(presid)
[1] 12614
Browse[2]> length(object$survey.design$pweights)
[1] 8397


and including vs excluding the na.action=na.exclude gives you a
slightly different dispersion parameter calculation

(Dispersion parameter for binomial family taken to be 0.7756235)

(Dispersion parameter for binomial family taken to be 0.7849244)


not sure if the two 

Re: [R] Significance of Svyrepdesign Object Warning

2016-10-27 Thread William Dunlap via R-help
For, now I would just use na.action=na.omit instead of na.exclude.  My
comments were mainly for the package author.

Bill Dunlap
TIBCO Software
wdunlap tibco.com

On Thu, Oct 27, 2016 at 5:53 PM, Courtney Benjamin 
wrote:

> Hello Mr. Dunlap,
>
> I have gone back and re-read the responses to my question.  I am
> interested in trying to apply your recommendation so I am doing things
> correctly; however I am not sure how to go about doing it within my code.
> It appears that you are digging quite deeply into R where I am not yet
> familiar.  I am including a reproducible example; would you be willing to
> show an example of how it would be done?  I greatly appreciate your
> advisement and time.
>
> Sincerely,
>
> Courtney
>
>
> library(RCurl)
> library(survey)
> data <- getURL("https://raw.githubusercontent.com/
> cbenjamin1821/careertech-ed/master/elsq1adj.csv")
> elsq1ch <- read.csv(text = data)
> #Specifying the svyrepdesign object which applies the BRR weights
> elsq1ch_brr<-svrepdesign(variables = elsq1ch[,1:16], repweights =
> elsq1ch[,18:217], weights = elsq1ch[,17], combined.weights = TRUE, type =
> "BRR")
> elsq1ch_brr
> #Logistic regression call which yields a warning regarding svyrepdesign
> object
> allCC <-svyglm(formula=F3ATTAINB~F1PARED+BYINCOME+F1RACE+F1SEX+
> F1RGPP2+F1HIMATH+F1RTRCC,family="binomial",design=
> elsq1ch_brr,subset=BYSCTRL==1==1,na.action=na.exclude)
> summary(allCC)
>
>
> ​
>
>
> Courtney Benjamin
>
> Broome-Tioga BOCES
>
> Automotive Technology II Teacher
>
> Located at Gault Toyota
>
> Doctoral Candidate-Educational Theory & Practice
>
> State University of New York at Binghamton
>
> cbenj...@btboces.org
>
> 607-763-8633
> --
> *From:* William Dunlap 
> *Sent:* Sunday, October 23, 2016 2:24 PM
> *To:* Anthony Damico
> *Cc:* Courtney Benjamin; r-help@r-project.org; Thomas Lumley
> *Subject:* Re: [R] Significance of Svyrepdesign Object Warning
>
> The immediate problem could be solved by changing the following lines in
> survey:::summary.svrepglm from
> presid <- resid(object, "pearson")
> dispersion <- sum(object$survey.design$pweights * presid^2,
> na.rm = TRUE)/sum(object$survey.design$pweights)
> to
> presid <- resid(object, "pearson")
> pweights <- naresid(object$na.action, object$survey.design$pweights)
> dispersion <- sum(pweights * presid^2, na.rm = TRUE)/sum(pweights,
> na.rm = TRUE)
>
> 'naresid' uses the information from na.exclude to match up the residuals
> with the row in the data that they correspond to.  resid() calls it so it
> should
> also be applied to pweights so they line up correctly.
>
>
>
>
> Bill Dunlap
> TIBCO Software
> wdunlap tibco.com
>
> On Sun, Oct 23, 2016 at 11:17 AM, Anthony Damico 
> wrote:
>
>> hi, great example.  i am ccing survey package author/maintainer dr.
>> lumley.  why do you have `na.action=na.exclude`?  if you remove it, things
>> work as expected--
>>
>>
>> library(RCurl)
>> library(survey)
>> data <- getURL("
>> https://raw.githubusercontent.com/cbenjamin1821/careertech-e
>> d/master/elsq1adj.csv
>> ")
>> elsq1ch <- read.csv(text = data)
>> #Specifying the svyrepdesign object which applies the BRR weights
>> elsq1ch_brr<-svrepdesign(variables = elsq1ch[,1:16], repweights =
>> elsq1ch[,18:217], weights = elsq1ch[,17], combined.weights = TRUE, type =
>> "BRR")
>> elsq1ch_brr
>> #Logistic regression call which yields a warning regarding
>> svyrepdesign
>> object
>>
>> # your warning
>> a <-
>> svyglm(formula=F3ATTAINB~F1PARED+BYINCOME+F1RACE+F1SEX+F1RGP
>> P2+F1HIMATH+F1RTRCC,family="binomial",design=elsq1ch_brr,
>> subset=BYSCTRL==1==1,na.action=na.exclude)
>> summary(a)
>>
>> # works fine
>> a <-
>> svyglm(formula=F3ATTAINB~F1PARED+BYINCOME+F1RACE+F1SEX+F1RGP
>> P2+F1HIMATH+F1RTRCC,family="binomial",design=elsq1ch_brr,
>> subset=BYSCTRL==1==1)
>> summary(a)
>>
>>
>>
>> the mismatch of vectors generating that warning happens inside
>>
>> debug(survey:::summary.svrepglm)
>>
>> [..snip..]
>>
>> Browse[2]> length(presid)
>> [1] 12614
>> Browse[2]> length(object$survey.design$pweights)
>> [1] 8397
>>
>>
>> and including vs excluding the na.action=na.exclude gives you a
>> slightly different dispersion parameter calculation
>>
>> (Dispersion parameter for binomial family taken to be 0.7756235)
>>
>> (Dispersion parameter for binomial family taken to be 0.7849244)
>>
>>
>> not sure if the two survey:::residuals.sv* methods should deal with the
>> na.action= parameter?
>>
>>
>> thanks
>>
>> On Sun, Oct 23, 2016 at 11:56 AM, Courtney Benjamin > >
>> wrote:
>>
>> > Hello R Users,
>> >
>> > I am using Lumley's Survey Package in R to analyze complex survey data
>> > that involves 200 balanced repeated replicate (BRR) weight variables.  I
>> > have ensured that my svyrepdesign object that 

Re: [R] Significance of Svyrepdesign Object Warning

2016-10-27 Thread Courtney Benjamin
Hello Mr. Dunlap,

I have gone back and re-read the responses to my question.  I am interested in 
trying to apply your recommendation so I am doing things correctly; however I 
am not sure how to go about doing it within my code.  It appears that you are 
digging quite deeply into R where I am not yet familiar.  I am including a 
reproducible example; would you be willing to show an example of how it would 
be done?  I greatly appreciate your advisement and time.

Sincerely,

Courtney


library(RCurl)
library(survey)
data <- 
getURL("https://raw.githubusercontent.com/cbenjamin1821/careertech-ed/master/elsq1adj.csv;)
elsq1ch <- read.csv(text = data)
#Specifying the svyrepdesign object which applies the BRR weights
elsq1ch_brr<-svrepdesign(variables = elsq1ch[,1:16], repweights = 
elsq1ch[,18:217], weights = elsq1ch[,17], combined.weights = TRUE, type = "BRR")
elsq1ch_brr
#Logistic regression call which yields a warning regarding svyrepdesign object
allCC 
<-svyglm(formula=F3ATTAINB~F1PARED+BYINCOME+F1RACE+F1SEX+F1RGPP2+F1HIMATH+F1RTRCC,family="binomial",design=elsq1ch_brr,subset=BYSCTRL==1==1,na.action=na.exclude)
summary(allCC)


​


Courtney Benjamin

Broome-Tioga BOCES

Automotive Technology II Teacher

Located at Gault Toyota

Doctoral Candidate-Educational Theory & Practice

State University of New York at Binghamton

cbenj...@btboces.org

607-763-8633


From: William Dunlap 
Sent: Sunday, October 23, 2016 2:24 PM
To: Anthony Damico
Cc: Courtney Benjamin; r-help@r-project.org; Thomas Lumley
Subject: Re: [R] Significance of Svyrepdesign Object Warning

The immediate problem could be solved by changing the following lines in 
survey:::summary.svrepglm from
presid <- resid(object, "pearson")
dispersion <- sum(object$survey.design$pweights * presid^2,
na.rm = TRUE)/sum(object$survey.design$pweights)
to
presid <- resid(object, "pearson")
pweights <- naresid(object$na.action, object$survey.design$pweights)
dispersion <- sum(pweights * presid^2, na.rm = TRUE)/sum(pweights,
na.rm = TRUE)

'naresid' uses the information from na.exclude to match up the residuals
with the row in the data that they correspond to.  resid() calls it so it should
also be applied to pweights so they line up correctly.




Bill Dunlap
TIBCO Software
wdunlap tibco.com

On Sun, Oct 23, 2016 at 11:17 AM, Anthony Damico 
> wrote:
hi, great example.  i am ccing survey package author/maintainer dr.
lumley.  why do you have `na.action=na.exclude`?  if you remove it, things
work as expected--


library(RCurl)
library(survey)
data <- getURL("
https://raw.githubusercontent.com/cbenjamin1821/careertech-ed/master/elsq1adj.csv
")
elsq1ch <- read.csv(text = data)
#Specifying the svyrepdesign object which applies the BRR weights
elsq1ch_brr<-svrepdesign(variables = elsq1ch[,1:16], repweights =
elsq1ch[,18:217], weights = elsq1ch[,17], combined.weights = TRUE, type =
"BRR")
elsq1ch_brr
#Logistic regression call which yields a warning regarding svyrepdesign
object

# your warning
a <-
svyglm(formula=F3ATTAINB~F1PARED+BYINCOME+F1RACE+F1SEX+F1RGPP2+F1HIMATH+F1RTRCC,family="binomial",design=elsq1ch_brr,subset=BYSCTRL==1==1,na.action=na.exclude)
summary(a)

# works fine
a <-
svyglm(formula=F3ATTAINB~F1PARED+BYINCOME+F1RACE+F1SEX+F1RGPP2+F1HIMATH+F1RTRCC,family="binomial",design=elsq1ch_brr,subset=BYSCTRL==1==1)
summary(a)



the mismatch of vectors generating that warning happens inside

debug(survey:::summary.svrepglm)

[..snip..]

Browse[2]> length(presid)
[1] 12614
Browse[2]> length(object$survey.design$pweights)
[1] 8397


and including vs excluding the na.action=na.exclude gives you a
slightly different dispersion parameter calculation

(Dispersion parameter for binomial family taken to be 0.7756235)

(Dispersion parameter for binomial family taken to be 0.7849244)


not sure if the two survey:::residuals.sv* methods should 
deal with the
na.action= parameter?


thanks

On Sun, Oct 23, 2016 at 11:56 AM, Courtney Benjamin 
>
wrote:

> Hello R Users,
>
> I am using Lumley's Survey Package in R to analyze complex survey data
> that involves 200 balanced repeated replicate (BRR) weight variables.  I
> have ensured that my svyrepdesign object that specifies the application of
> the BRR weights to the data set is accurate and I have matched the
> published standard errors of the data set.
>
> When doing a logistic regression through the svyglm call, I receive the
> following warning:
>
> In object$survey.design$pweights * presid^2 :
>   longer object length is not a multiple of shorter object length?
> I have search around quite a bit online and have not been able to find any
> good interpretation of its 

Re: [R] Reg. Error: could not find function "lsei" in limSolve library

2016-10-27 Thread David Winsemius

> On Oct 27, 2016, at 7:12 AM, arunkumar.govindar...@hsbc.co.in wrote:
> 
> Hi,
> 
> I tried to load package from local zip folder in R logic and it worked.
> 
>> utils:::menuInstallLocal()
> package ‘limSolve’ successfully unpacked and MD5 sums checked
> 
> when tried to load.. it says,
> 
>> local({pkg <- select.list(sort(.packages(all.available = 
> TRUE)),graphics=TRUE)
> + if(nchar(pkg)) library(pkg, character.only=TRUE)})
> Error in loadNamespace(j <- i[[1L]], c(lib.loc, .libPaths()), versionCheck 
> = vI[[j]]) : 
>  there is no package called ‘lpSolve’
> In addition: Warning message:
> package ‘limSolve’ was built under R version 3.2.5 
> Error: package or namespace load failed for ‘limSolve’

I do not see the error you are referencing about in your subject line.

The error message you are posting says that if you do not have the R package 
dependencies for a package in your library directories, it fails to install. 
(Read the error messages completely.)

And do read the Posting Guide.

> 
> But my R version is 3.1.2, so can someone tell me, how to load the 
> package? thx

If your desired package will not install or load after installation in an 
outdated version of R, then you need to install a copy from the Archives.

-- 
Best;
David.

> 
> Regards,
> Arun
> 
> 
> 
> The Hongkong and Shanghai Banking Corporation Limited
> whose registered address is 1 Queen's Road Central, Hong Kong
> 
> 
> 
> 
> -
> ***
> This e-mail is confidential. It may also be legally privileged.
> If you are not the addressee you may not copy, forward, disclose
> or use any part of it. If you have received this message in error,
> please delete it and all copies from your system and notify the
> sender immediately by return e-mail.
> 
> Internet communications cannot be guaranteed to be timely,
> secure, error or virus-free. The sender does not accept liability
> for any errors or omissions.
> ***
> "SAVE PAPER - THINK BEFORE YOU PRINT!"
> 
>   [[alternative HTML version deleted]]
> 
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

David Winsemius
Alameda, CA, USA

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

[R-es] warning en actualizacion

2016-10-27 Thread Sebastian Kruk
Hola usuarios-R,

Tengo un problema con la actualización.

En mi maquina que tiene Windows 10 tengo instalado R-3.3.1 de 64 bits y 32
bits.

Cuando quiero actualizar me salen las siguientes advertencias:

> update.packages(ask='graphics',checkBuilt=TRUE)
--- Please select a CRAN mirror for use in this session ---
Warning: package 'cluster' in library 'C:/Program Files/R/R-3.3.1/library'
will not be updated
Warning: package 'codetools' in library 'C:/Program
Files/R/R-3.3.1/library' will not be updated
Warning: package 'foreign' in library 'C:/Program Files/R/R-3.3.1/library'
will not be updated
Warning: package 'lattice' in library 'C:/Program Files/R/R-3.3.1/library'
will not be updated
Warning: package 'Matrix' in library 'C:/Program Files/R/R-3.3.1/library'
will not be updated
Warning: package 'mgcv' in library 'C:/Program Files/R/R-3.3.1/library'
will not be updated
Warning: package 'survival' in library 'C:/Program Files/R/R-3.3.1/library'
will not be updated

No es un problema de derechos administrativos pues enseguida de las
advertencias anteriores instalé mFilter:

> utils:::menuInstallPkgs()
probando la URL '
https://cloud.r-project.org/bin/windows/contrib/3.3/mFilter_0.1-3.zip'
Content type 'application/zip' length 81769 bytes (79 KB)
downloaded 79 KB

package ‘mFilter’ successfully unpacked and MD5 sums checked

The downloaded binary packages are in
C:\Users\USER\AppData\Local\Temp\RtmpCsd6xo\downloaded_packages

¿Será un problema de R o que?

Saludos,

Sebastián.

[[alternative HTML version deleted]]

___
R-help-es mailing list
R-help-es@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-help-es

Re: [R-es] Encontrar la primera columna no NA

2016-10-27 Thread Jorge I Velez
Excelente!

Aqui hay otra aproximación en base:

R> t <- Sys.time()
R> out <- apply(as.matrix(dat), 1, function(x) x[!is.na(x)][1])
R> difftime(Sys.time(), t)
## Time difference of 0.656173 secs

Nada mal :)

Saludos,
Jorge.-


2016-10-27 11:42 GMT-05:00 Carlos J. Gil Bellosta :

> Las operaciones con columnas de data.frames (y sus variantes modernas) son
> muy caras. Así que:
>
> t <- Sys.time()
>
> tmp <- (as.matrix(dat))
> cols <- col(tmp)
> cols[is.na(tmp)] <- Inf
> my.cols <- apply(cols, 1, min)
> my.values <- tmp[cbind(1:nrow(tmp), my.cols)]
>
> difftime(Sys.time(), t)
>
> Y una pregunta: ¿alguien programa en R base todavía?
>
> Un saludo,
>
> Carlos J. Gil Bellosta
> http://www.datanalytics.com
>
> El 27 de octubre de 2016, 18:11, Olivier Nuñez  escribió:
>
> >
> > Por último, utilizando la indexación lineal de matriz 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 Uno0.93520715
> >  2:   2 Uno0.85930634
> >  3:   3 dos0.13521503
> >  4:   4 Uno0.86996341
> >  5:   5 dos0.65879889
> > ---
> >  6:   6 Uno0.94728423
> >  7:   7 Uno0.24088571
> >  8:   8 Uno0.07458581
> >  9:   9 Uno0.30535050
> > 10:  10 Uno0.54640585
> > > difftime( Sys.time(), t)
> > Time difference of 0.329 secs
> > >
> > - Mensaje original -
> > De: Javier Villacampa González 
> > Para: Olivier Nuñez 
> > CC: R ayuda 
> > Enviado: Thu, 27 Oct 2016 17:17:12 +0200 (CEST)
> > Asunto: Re: [R-es] Encontrar la primera columna no NA
> >
> > Hemos mejorado bastante desde el inicio. Pero aun andamos lejos. Igual es
> > por el merge que hago. Seguire mirando
> > library(microbenchmark)
> > N <- 1e1
> > tabla <-
> >   microbenchmark(
> > # JVG_dplyr ={
> > #   dat %>%
> > # apply( MARGIN = 1, FUN =
> > #  function(x){
> > #which( !is.na(x)  ) %>%  min( na.rm = TRUE ) %>%
> > return()
> > #}
> > # )
> > #   dat[ , First_month := First_month]
> > #   N_for <- length( unique(First_month ))
> > #   for( j in 1:N_for){
> > # x <- dat[  First_month == j,  j,  with = FALSE]
> > # dat[ First_month == j , Value_First_month := x ]
> > #   }
> > # },
> > JVG ={
> >   dat <-
> > data.table( Uno= sample( c(runif(numero) , rep(NA , numero
> /2e0
> > )) , size = numero ) ,
> > dos= sample( c(runif(numero) , rep(NA , numero
> /1e1
> > )) , size = numero ) ,
> > tres   = sample( c(runif(numero) , rep(NA , numero
> /2e1
> > )) , size = numero ) ,
> > 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 )
> > )
> >
> >   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 <- dat[  First_month == j,  j,  with = FALSE]
> > dat[ First_month == j , Value_First_month := x ]
> >   }
> > },
> > Olivier ={
> > dat <-
> >   data.table( Uno= sample( c(runif(numero) , rep(NA , numero /2e0
> > )) , size = numero ) ,
> >   dos= sample( c(runif(numero) , rep(NA , numero /1e1
> > )) , size = numero ) ,
> >   tres   = sample( c(runif(numero) , rep(NA , numero /2e1
> > )) , size = numero ) ,
> >   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 )
> >   )
> >   dat[,First_month   := apply(X = .SD,MARGIN = 1,FUN =
> function(x)
> > colnames(.SD)[min(which(!is.na(x)))])]
> >   dat[,Value_First_month := apply(X = .SD,MARGIN = 1,FUN =
> function(x)
> > x[min(which(!is.na(x)))])]
> > },
> >

Re: [R] Finding starting values for the parameters using nls() or nls2()

2016-10-27 Thread dave fournier

>
>> On Oct 25, 2016, at 9:29 AM, dave fournier  
wrote:

>>
>>
>>
>> Unfortunately this problem does not appear to be well posed.
>>
>>Retention = (b0*Area^(th+1))^b
>>
>> If b0, th, and b are the parameter only the product (th+1)*b is 
determined.

>>
>> This comes from noting that powers satisfy
>>
>>
>>
>>(a^b)^c  =  a^(b*c)
>>
>>
>>
>> So your model can be written as
>>
>>
>>
>>  (b0^b) * Area^((th+1)*b)
>>
>
>... which nicely completes the thread since one model had:
>
>th1   =  9.1180e-01
> b01=5.2104e+00
> b11 =  -4.6725e-04
>(th1+1)*b11
>[1] -0.0008932885
>
>
> b0  = 5.2104466   ;b1 =   -0.0004672   ;  th =  0.9118029
>((th+1)*b1)
>[1] -0.0008931943
>
>So both the R's nls2 and AD_MOdel_Builder results yield that same 
predictions for any given data point at least up to four decimal places.

>
>So perhaps there was some other physical interpretation of those 
parameters and there exists an underlying theory that would support 
adding some extra constraints?

>
>--
>>David Winsemius
>Alameda, CA, USA

I'm not really sure what your point is. The OP has two models. One is well
posed and the other is not. I was discussing solution of the former model
which is well posed.  The form of the model, using a, b, and t and x,y to
simplify the expression is

y  = exp( a * exp(b * x^t) )

My point is that there are many models like this where the obvious
parameterization (something like the parameters the user is interested
in) leads to parameter estimates with highly correlated errors.
This does not necessarily mean that
the model is badly determined. The model exists independent of the
particular parameterization. To fix  the ideas assume there are n 
observations

(x_i,y_i)  and simplify by assuming that x_1<=x_2<=...<=x_n
(but not all equal lets hope)

A stable parameterization of the model can often be obtained by
picking as new parameters y1 and yn where y1 and yn are the predicted 
values for y_1 and y_n, that is


   y1  = exp( a * exp(b * x_1^t) )
   yn  = exp( a * exp(b * x_n^t) )

Then one solves for some of the original model parameters in terms of y1 
and yn.

The particular way this is done depends on the model. Often some has some
linear parameters and the procedure is easy. For this model as I showed
one can solve for a and b in terms of y1 and yn.
Then one can fit the model easily with AD Model Builder or
nls2 using this parameterization. nls2 provides the standard errors for
the parameter estimates.  The AD Model Builder solution provides the
estimated variance covariance matrix of the parameter estimates via the
standard maximum likelihood Hessian calculations. It also provides the
covariance for any desired dependent variable.  So one can fit the model
using y1,yn, and t and get the covariance matrix for a,b, and t
in one step. In nls2 one needs to fit the model using y1,yn and then
solve for a and b and run the model again from that point.  That is no big
deal, and I showed how to do it, but it is one more step for the user.

It is interesting to see the correlation matrix for the parameter estimates
and the dependent variables.
std dev  correlation
1  logt -9.233e-02 3.4026e-01  1.
2  c9.7164e-01 3.7006e-02 -0.2690  1.
3  d1.1010e+00 1.7852e-01 -0.7495  0.0325  1.000
4  t9.1180e-01 3.1025e-01  1. -0.2690 -0.749  1.
5  a5.2104e+00 4.3404e-01 -0.9781  0.4191  0.621 -0.9781  1.000
6  b   -4.6725e-04 1.1714e-03  0.9994 -0.2836 -0.726  0.9994 -0.984 1.00

Here the independent variable are c, d, and logt
where y1=c*y_1  y2=d*y2
That is just an additional thing so that one can start with c=1 and d=1
Also logt is used where t=exp(logt) which makes sure t>0.
Notice that the correlation between c and d is 0.0325 which is small.


If  a and b were the parameters of the model

4   t9.1180e-01 3.1025e-01   1.
5   a5.2104e+00 4.3404e-01   -0.9781  1.000
6   b   -4.6725e-04 1.1714e-030.9994 -0.984  1.00

One can see how close to 1 and -1 the correlations are.

Notice that the parameter b is very badly determined.
So rather than saying the model is no good one sees that
the model is no good if one want to get information about
the parameter b. In contrast the parameter a is fairly well
determined and the parameter t is "kind of" determined.

  Because of this parameter confounding nls2 is extremely sensitive
  to the starting parameter values using this parameterization.
  If I change the parameters by about 15% or less as below

  #b0start=5.210445
  #b1_start=-0.0004672373
  #th_start=0.911804
  b0_start=5.7
  b1_start=-0.00055
  th_start=1.05

I get the dreaded

Error in (function (formula, data = parent.frame(), start, control = 
nls.control(),  :

  singular gradient

So there is nothing wrong with either the data or the model. The model
just needs to be given a stable parameterization.

__
R-help@r-project.org mailing list -- To 

[R] Reg. Error: could not find function "lsei" in limSolve library

2016-10-27 Thread arunkumar . govindaraju
Hi,

I tried to load package from local zip folder in R logic and it worked.

> utils:::menuInstallLocal()
package ‘limSolve’ successfully unpacked and MD5 sums checked

when tried to load.. it says,

> local({pkg <- select.list(sort(.packages(all.available = 
TRUE)),graphics=TRUE)
+ if(nchar(pkg)) library(pkg, character.only=TRUE)})
Error in loadNamespace(j <- i[[1L]], c(lib.loc, .libPaths()), versionCheck 
= vI[[j]]) : 
  there is no package called ‘lpSolve’
In addition: Warning message:
package ‘limSolve’ was built under R version 3.2.5 
Error: package or namespace load failed for ‘limSolve’

But my R version is 3.1.2, so can someone tell me, how to load the 
package? thx

Regards,
Arun



The Hongkong and Shanghai Banking Corporation Limited
whose registered address is 1 Queen's Road Central, Hong Kong




-
***
This e-mail is confidential. It may also be legally privileged.
If you are not the addressee you may not copy, forward, disclose
or use any part of it. If you have received this message in error,
please delete it and all copies from your system and notify the
sender immediately by return e-mail.

Internet communications cannot be guaranteed to be timely,
secure, error or virus-free. The sender does not accept liability
for any errors or omissions.
***
"SAVE PAPER - THINK BEFORE YOU PRINT!"

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

[R] How to create a list of trellis objects for grid.arrange()

2016-10-27 Thread Agustin Lobo
Given
require(raster)
require(sp)
require(gridExtra)

f <- system.file("external/test.grd", package="raster")
r <- raster(f)
p1 <- spplot(r)
p2 <- spplot(r)

I would like to plot the equivalent to

grid.arrange(p1,p2,ncol=1,nrow=2)

but keeping the trellis objects p1 and p2 within one single object (as
in practice I have many objects generated within a for() loop).

The following used to work:
ps <- c(p1,p2)
grid.arrange(ps,ncol=1,nrow=2)

but does not work any more.

How should I combine p1 and p2 into one single object that would be
accepted by grid.arrange?

Thanks
-- 
Agustin Lobo
aloboa...@gmail.com

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R-es] Encontrar la primera columna no NA

2016-10-27 Thread Olivier Nuñez

Por último, utilizando la indexación lineal de matriz 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 Uno0.93520715
 2:   2 Uno0.85930634
 3:   3 dos0.13521503
 4:   4 Uno0.86996341
 5:   5 dos0.65879889
---  
 6:   6 Uno0.94728423
 7:   7 Uno0.24088571
 8:   8 Uno0.07458581
 9:   9 Uno0.30535050
10:  10 Uno0.54640585
> difftime( Sys.time(), t)
Time difference of 0.329 secs
> 
- Mensaje original -
De: Javier Villacampa González 
Para: Olivier Nuñez 
CC: R ayuda 
Enviado: Thu, 27 Oct 2016 17:17:12 +0200 (CEST)
Asunto: Re: [R-es] Encontrar la primera columna no NA

Hemos mejorado bastante desde el inicio. Pero aun andamos lejos. Igual es
por el merge que hago. Seguire mirando
library(microbenchmark)
N <- 1e1
tabla <-
  microbenchmark(
# JVG_dplyr ={
#   dat %>%
# apply( MARGIN = 1, FUN =
#  function(x){
#which( !is.na(x)  ) %>%  min( na.rm = TRUE ) %>%
return()
#}
# )
#   dat[ , First_month := First_month]
#   N_for <- length( unique(First_month ))
#   for( j in 1:N_for){
# x <- dat[  First_month == j,  j,  with = FALSE]
# dat[ First_month == j , Value_First_month := x ]
#   }
# },
JVG ={
  dat <-
data.table( Uno= sample( c(runif(numero) , rep(NA , numero /2e0
)) , size = numero ) ,
dos= sample( c(runif(numero) , rep(NA , numero /1e1
)) , size = numero ) ,
tres   = sample( c(runif(numero) , rep(NA , numero /2e1
)) , size = numero ) ,
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 )
)

  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 <- dat[  First_month == j,  j,  with = FALSE]
dat[ First_month == j , Value_First_month := x ]
  }
},
Olivier ={
dat <-
  data.table( Uno= sample( c(runif(numero) , rep(NA , numero /2e0
)) , size = numero ) ,
  dos= sample( c(runif(numero) , rep(NA , numero /1e1
)) , size = numero ) ,
  tres   = sample( c(runif(numero) , rep(NA , numero /2e1
)) , size = numero ) ,
  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 )
  )
  dat[,First_month   := apply(X = .SD,MARGIN = 1,FUN = function(x)
colnames(.SD)[min(which(!is.na(x)))])]
  dat[,Value_First_month := apply(X = .SD,MARGIN = 1,FUN = function(x)
x[min(which(!is.na(x)))])]
},
Olivier2={
  dat <-
data.table( Uno= sample( c(runif(numero) , rep(NA , numero /2e0
)) , size = numero ) ,
dos= sample( c(runif(numero) , rep(NA , numero /1e1
)) , size = numero ) ,
tres   = sample( c(runif(numero) , rep(NA , numero /2e1
)) , size = numero ) ,
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 )
)

  dat[,jugador:=1:.N]
  dat2=melt(dat,id.vars="jugador")
  setkey(dat2,jugador)
  dat2[,index:=min(which(!is.na(value))),by=jugador]
  dat3 <- dat2[,list(First_month_Olivier
=variable[index[1]],Value_First_month_Olivier =value[index[1]]),by=jugador]
  setkey(x = dat, jugador)
  dat0 <- merge( x = dat, y = dat3, all.x = TRUE, all.y = FALSE)

},
times = N, unit = "s")

tabla %>%  print
beepr::beep(3)

# Unit: seconds
#   expr   minlq  meanmedianuq  max
neval
# JVG   0.6479002 0.7518933 0.8673007 

Re: [R] How to put below code in Automator in iOS

2016-10-27 Thread Sarah Goslee
You should probably ask this on the Mac R-help list, since it's not a
general R question and that's where you are likely to find people who
know the answer:
https://stat.ethz.ch/mailman/listinfo/r-sig-mac

Sarah

On Thu, Oct 27, 2016 at 11:05 AM, Christofer Bogaso
 wrote:
> Hi,
>
> I have a piece of code available here
>
> http://mcu.edu.tw/~chenmh/teaching/project/r/reference/RTclTkExamples/radiobuttons.html
>
> Now I put that code in a .R file and then created an .app file in Mac
> using Automator as explained below
>
> https://www.r-bloggers.com/how-to-source-an-r-script-automatically-on-a-mac-using-automator-and-ical/
>
> Surprisingly what I see is that, when I put that R code in a .app
> file, R fails to pop up the input window, which otherwise is fine when
> I just copy paste that code in R window.
>
> Could you please help if I need to have anything extra so that my .app
> will be able to take the input.
>
> Thanks for your time.
>

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R-es] RV: pregunta

2016-10-27 Thread Carlos J. Gil Bellosta
Hola, ¿qué tal?

¿No te vale epiDisplay
?

Un saludo,

Carlos J. Gil Bellosta
http://www.datanalytics.com

El 27 de octubre de 2016, 11:56, Dr. José A. Betancourt Bethencourt <
josebetancourt@infomed.sld.cu> escribió:

>
>
>
>
> De: Dr. José A. Betancourt Bethencourt [mailto:jbetanco...@iscmc.cmw.
> sld.cu]
>
> Enviado el: jueves, 27 de octubre de 2016 05:56
> Para: 'r-help-es@r-project.org' 
> Asunto: pregunta
>
>
>
> Estimados, el paquete EPICALC ya no funciona, ¿existe alguna manera de
> utilizarlo sin tener que regresar a una vieja versión de r? Es que para la
> docencia es muy útil
>
> Saludos
>
> José
>
>
>
> --
> Este mensaje le ha llegado mediante el servicio de correo electronico que
> ofrece Infomed para respaldar el cumplimiento de las misiones del Sistema
> Nacional de Salud. La persona que envia este correo asume el compromiso de
> usar el servicio a tales fines y cumplir con las regulaciones establecidas
>
> Infomed: http://www.sld.cu/
>
>
>
>
> [[alternative HTML version deleted]]
>
>
> ___
> R-help-es mailing list
> R-help-es@r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-help-es
>

[[alternative HTML version deleted]]

___
R-help-es mailing list
R-help-es@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-help-es


Re: [R] How to put below code in Automator in iOS

2016-10-27 Thread S Ellison
>From 'An introduction to R' in the html help system:
"If you just want to run a file foo.R of R commands, the recommended way is to 
use R CMD BATCH foo.R. "
There is also a short section on 'Invoking R under OS X' in the 'Introduction 
to R'; it may help.

S Ellison


> -Original Message-
> From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Christofer
> Bogaso
> Sent: 27 October 2016 16:06
> To: r-help
> Subject: [R] How to put below code in Automator in iOS
> 
> Hi,
> 
> I have a piece of code available here
> 
> http://mcu.edu.tw/~chenmh/teaching/project/r/reference/RTclTkExamples
> /radiobuttons.html
> 
> Now I put that code in a .R file and then created an .app file in Mac using
> Automator as explained below
> 
> https://www.r-bloggers.com/how-to-source-an-r-script-automatically-on-a-
> mac-using-automator-and-ical/
> 
> Surprisingly what I see is that, when I put that R code in a .app file, R 
> fails to
> pop up the input window, which otherwise is fine when I just copy paste that
> code in R window.
> 
> Could you please help if I need to have anything extra so that my .app will be
> able to take the input.
> 
> Thanks for your time.
> 
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-
> guide.html
> and provide commented, minimal, self-contained, reproducible code.


***
This email and any attachments are confidential. Any use...{{dropped:8}}

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R-es] RV: pregunta

2016-10-27 Thread Dr. José A. Betancourt Bethencourt
 

 

De: Dr. Jos� A. Betancourt Bethencourt [mailto:jbetanco...@iscmc.cmw.sld.cu]

Enviado el: jueves, 27 de octubre de 2016 05:56
Para: 'r-help-es@r-project.org' 
Asunto: pregunta

 

Estimados, el paquete EPICALC ya no funciona, �existe alguna manera de
utilizarlo sin tener que regresar a una vieja versi�n de r? Es que para la
docencia es muy �til

Saludos

Jos�



--
Este mensaje le ha llegado mediante el servicio de correo electronico que 
ofrece Infomed para respaldar el cumplimiento de las misiones del Sistema 
Nacional de Salud. La persona que envia este correo asume el compromiso de usar 
el servicio a tales fines y cumplir con las regulaciones establecidas

Infomed: http://www.sld.cu/




[[alternative HTML version deleted]]

___
R-help-es mailing list
R-help-es@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-help-es

Re: [R-es] Encontrar la primera columna no NA

2016-10-27 Thread Javier Villacampa González
Hemos mejorado bastante desde el inicio. Pero aun andamos lejos. Igual es
por el merge que hago. Seguire mirando
library(microbenchmark)
N <- 1e1
tabla <-
  microbenchmark(
# JVG_dplyr ={
#   dat %>%
# apply( MARGIN = 1, FUN =
#  function(x){
#which( !is.na(x)  ) %>%  min( na.rm = TRUE ) %>%
return()
#}
# )
#   dat[ , First_month := First_month]
#   N_for <- length( unique(First_month ))
#   for( j in 1:N_for){
# x <- dat[  First_month == j,  j,  with = FALSE]
# dat[ First_month == j , Value_First_month := x ]
#   }
# },
JVG ={
  dat <-
data.table( Uno= sample( c(runif(numero) , rep(NA , numero /2e0
)) , size = numero ) ,
dos= sample( c(runif(numero) , rep(NA , numero /1e1
)) , size = numero ) ,
tres   = sample( c(runif(numero) , rep(NA , numero /2e1
)) , size = numero ) ,
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 )
)

  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 <- dat[  First_month == j,  j,  with = FALSE]
dat[ First_month == j , Value_First_month := x ]
  }
},
Olivier ={
dat <-
  data.table( Uno= sample( c(runif(numero) , rep(NA , numero /2e0
)) , size = numero ) ,
  dos= sample( c(runif(numero) , rep(NA , numero /1e1
)) , size = numero ) ,
  tres   = sample( c(runif(numero) , rep(NA , numero /2e1
)) , size = numero ) ,
  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 )
  )
  dat[,First_month   := apply(X = .SD,MARGIN = 1,FUN = function(x)
colnames(.SD)[min(which(!is.na(x)))])]
  dat[,Value_First_month := apply(X = .SD,MARGIN = 1,FUN = function(x)
x[min(which(!is.na(x)))])]
},
Olivier2={
  dat <-
data.table( Uno= sample( c(runif(numero) , rep(NA , numero /2e0
)) , size = numero ) ,
dos= sample( c(runif(numero) , rep(NA , numero /1e1
)) , size = numero ) ,
tres   = sample( c(runif(numero) , rep(NA , numero /2e1
)) , size = numero ) ,
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 )
)

  dat[,jugador:=1:.N]
  dat2=melt(dat,id.vars="jugador")
  setkey(dat2,jugador)
  dat2[,index:=min(which(!is.na(value))),by=jugador]
  dat3 <- dat2[,list(First_month_Olivier
=variable[index[1]],Value_First_month_Olivier =value[index[1]]),by=jugador]
  setkey(x = dat, jugador)
  dat0 <- merge( x = dat, y = dat3, all.x = TRUE, all.y = FALSE)

},
times = N, unit = "s")

tabla %>%  print
beepr::beep(3)

# Unit: seconds
#   expr   minlq  meanmedianuq  max
neval
# JVG   0.6479002 0.7518933 0.8673007 0.8216553 0.9137195 1.25189110
# Olivier  2.9568197 3.6663586 3.9364770 3.9069826 4.5619519 4.68584210
# Olivier2 1.1316970 1.4463621 1.4735507 1.4874366 1.5681243 1.63171310
# E comparativa ---

El 27 de octubre de 2016, 15:39, Olivier Nuñez  escribió:

> 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 Uno0.93520715
>  2:   2 Uno0.85930634
>  3:   3 dos0.13521503
>  4:   4 Uno0.86996341
>  5:   5 dos0.65879889
> ---
>  6:   6 Uno0.94728423
>  7:   7 Uno0.24088571
>  8:   8 Uno0.07458581
>  9:   9 Uno0.30535050
> 10:  10 Uno0.54640585
> > difftime( Sys.time(), t)
> Time difference of 1.060787 secs
>
>
> - Mensaje original -
> De: "Olivier 

[R] How to put below code in Automator in iOS

2016-10-27 Thread Christofer Bogaso
Hi,

I have a piece of code available here

http://mcu.edu.tw/~chenmh/teaching/project/r/reference/RTclTkExamples/radiobuttons.html

Now I put that code in a .R file and then created an .app file in Mac
using Automator as explained below

https://www.r-bloggers.com/how-to-source-an-r-script-automatically-on-a-mac-using-automator-and-ical/

Surprisingly what I see is that, when I put that R code in a .app
file, R fails to pop up the input window, which otherwise is fine when
I just copy paste that code in R window.

Could you please help if I need to have anything extra so that my .app
will be able to take the input.

Thanks for your time.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R-es] Encontrar la primera columna no NA

2016-10-27 Thread Olivier Nuñez
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 Uno0.93520715
 2:   2 Uno0.85930634
 3:   3 dos0.13521503
 4:   4 Uno0.86996341
 5:   5 dos0.65879889
---  
 6:   6 Uno0.94728423
 7:   7 Uno0.24088571
 8:   8 Uno0.07458581
 9:   9 Uno0.30535050
10:  10 Uno0.54640585
> difftime( Sys.time(), t)
Time difference of 1.060787 secs


- Mensaje original -
De: "Olivier Nuñez" 
Para: "Javier Villacampa González" 
CC: "R ayuda" 
Enviados: Jueves, 27 de Octubre 2016 15:10:07
Asunto: Re: [R-es] Encontrar la primera columna no NA

Prueba lo siguiente, no es óptimo, pero creo va bastnate más rapido que los que 
mencionaste:

t <- Sys.time()
dat[,First_month := apply(.SD,1,function(x) 
colnames(.SD)[min(which(!is.na(x)))])]
dat[,Value_First_month := apply(.SD,1,function(x) x[min(which(!is.na(x)))])]
difftime( Sys.time(), t)

Time difference of 3.478778 secs


- Mensaje original -
De: "Javier Villacampa González" 
Para: "R ayuda" 
Enviados: Jueves, 27 de Octubre 2016 13:43:19
Asunto: [R-es] Encontrar la primera columna no NA

Imaginemos que tenemos una matriz con datos temporales por sujetos.
Pongamos que numero de veces que ha jugado una carta en un juego online. Y
que quiero saber cuantas veces jugo la carta el primer mes que estuvo en el
juego.

Pero claro mi matriz guarda los datos temporalmente de tal manera que:

# data.table( Enero = c( 1, 4, NA , NA , NA) , Febrero = c( 2, 6, 1, NA, NA
) , Marzo = c( 8,6,7,3, NA) ,  Abril = c( NA, 15, 5, 6,6 ))
#Enero Febrero Marzo Abril
# 1: 1   2 8NA
# 2: 4   6 615
# 3:NA   1 7 5
# 4:NA  NA 3 6
# 5:NA  NANA 6
# Suponiendo que cada fila es un jugador
# En este caso la solucion debería ser
# 1 para el primero que empezó en Enero
# 4 para el segundo jugador  que empezó en Enero
# 1 para el tercero  que empezó en Febrero
# 3 Para el cuarto  que empezó en Marzo
# 6 para el quinto  que empezó en Abril


A alguno se os ocurre una solucion más eficiente que la siguiente. Esto
seguro que con data table o dplyr se puede. Ya he quitados los pipes que
facilitan la lectura pero que no se llevan bien con data.table. Pero estoy
seguro que se puede mejorar más.

#===
# Como ejemplo de codigo
#===
# S Primera solucion --
# First not NA colum per subject
library(data.table)
library(dplyr)
set.seed(123456)
numero <- 1e5
dat <-
  data.table( Uno  = sample( c(runif(numero) , rep(NA , numero /2e0  )),
size = numero ) ,
dos= sample( c(runif(numero) , rep(NA , numero /1e1  )),
size = numero ) ,
tres   = sample( c(runif(numero) , rep(NA , numero /2e1 )) ,
size = numero ) ,
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 1:N_for){
  x <- dat[  First_month == j,  j,  with = FALSE]
  dat[ First_month == j , Value_First_month := x ]
}

dat %>%  print
# dat %>%  summary

cat( "===\n", difftime( Sys.time(), t, units =
"min") , " minutos que cuesta \n===\n" )
beepr::beep(3)
# E Primera solucion --




# S comparativa ---
library(microbenchmark)
N <- 1e2
tabla <-
  microbenchmark(
JVG_dplyr ={  dat %>%
apply( MARGIN = 1, FUN =
 function(x){
   which( !is.na(x)  ) %>%  min( na.rm = TRUE ) %>%
return()
   }
)
},
JVG ={
apply(X = dat,  MARGIN = 1, FUN =
 function(x){
   return(   min(  which( !is.na(x)  ),  na.rm = TRUE ) )
 }

Re: [R-es] Encontrar la primera columna no NA

2016-10-27 Thread Javier Villacampa González
Pues parece que para este caso en particular es mejor la solucon con el for
vectorizado. Aunque la verdad que la tuyaes muy buena de cara compresion y
comprensión de codigo. Igual si tuviese mas columnas la solucin la tuya
sería más rápida. Tendré que mirarlo.

library(microbenchmark)
N <- 1e1
tabla <-
  microbenchmark(
JVG ={
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 <- dat[  First_month == j,  j,  with = FALSE]
dat[ First_month == j , Value_First_month := x ]
  }
},
Olivier ={
  dat[,First_month   := apply(X = .SD,MARGIN = 1,FUN = function(x)
colnames(.SD)[min(which(!is.na(x)))])]
  dat[,Value_First_month := apply(X = .SD,MARGIN = 1,FUN = function(x)
x[min(which(!is.na(x)))])]
},
times = N, unit = "s")

tabla %>%  print
beepr::beep(3)

# Unit: seconds
#   expr  min   lq mean   median   uq  max neval
# JVG2.345127 2.440396 2.591505 2.509842 2.738680 3.01349810
# Olivier5.445869 5.454217 6.132737 6.212742 6.410948 7.00808510


El 27 de octubre de 2016, 15:10, Olivier Nuñez  escribió:

> Prueba lo siguiente, no es óptimo, pero creo va bastnate más rapido que
> los que mencionaste:
>
> t <- Sys.time()
> dat[,First_month := apply(.SD,1,function(x) colnames(.SD)[min(which(!is.na
> (x)))])]
> dat[,Value_First_month := apply(.SD,1,function(x) x[min(which(!is.na
> (x)))])]
> difftime( Sys.time(), t)
>
> Time difference of 3.478778 secs
>
>
> - Mensaje original -
> De: "Javier Villacampa González" 
> Para: "R ayuda" 
> Enviados: Jueves, 27 de Octubre 2016 13:43:19
> Asunto: [R-es] Encontrar la primera columna no NA
>
> Imaginemos que tenemos una matriz con datos temporales por sujetos.
> Pongamos que numero de veces que ha jugado una carta en un juego online. Y
> que quiero saber cuantas veces jugo la carta el primer mes que estuvo en el
> juego.
>
> Pero claro mi matriz guarda los datos temporalmente de tal manera que:
>
> # data.table( Enero = c( 1, 4, NA , NA , NA) , Febrero = c( 2, 6, 1, NA, NA
> ) , Marzo = c( 8,6,7,3, NA) ,  Abril = c( NA, 15, 5, 6,6 ))
> #Enero Febrero Marzo Abril
> # 1: 1   2 8NA
> # 2: 4   6 615
> # 3:NA   1 7 5
> # 4:NA  NA 3 6
> # 5:NA  NANA 6
> # Suponiendo que cada fila es un jugador
> # En este caso la solucion debería ser
> # 1 para el primero que empezó en Enero
> # 4 para el segundo jugador  que empezó en Enero
> # 1 para el tercero  que empezó en Febrero
> # 3 Para el cuarto  que empezó en Marzo
> # 6 para el quinto  que empezó en Abril
>
>
> A alguno se os ocurre una solucion más eficiente que la siguiente. Esto
> seguro que con data table o dplyr se puede. Ya he quitados los pipes que
> facilitan la lectura pero que no se llevan bien con data.table. Pero estoy
> seguro que se puede mejorar más.
>
> #===
> # Como ejemplo de codigo
> #===
> # S Primera solucion --
> 
> # First not NA colum per subject
> library(data.table)
> library(dplyr)
> set.seed(123456)
> numero <- 1e5
> dat <-
>   data.table( Uno  = sample( c(runif(numero) , rep(NA , numero /2e0  )),
> size = numero ) ,
> dos= sample( c(runif(numero) , rep(NA , numero /1e1  )),
> size = numero ) ,
> tres   = sample( c(runif(numero) , rep(NA , numero /2e1 )) ,
> size = numero ) ,
> 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 1:N_for){
>   x <- dat[  First_month == j,  j,  with = FALSE]
>   dat[ First_month == j , Value_First_month := x ]
> }
>
> dat %>%  print
> # dat %>%  summary
>
> cat( "===\n", difftime( Sys.time(), t, units =
> "min") , " minutos que cuesta \n===\n" )
> beepr::beep(3)
> # E Primera solucion --
> 
>
>
>
>
> # S comparativa --
> -
> library(microbenchmark)
> N <- 1e2
> tabla <-
> 

Re: [R-es] Encontrar la primera columna no NA

2016-10-27 Thread Olivier Nuñez
Prueba lo siguiente, no es óptimo, pero creo va bastnate más rapido que los que 
mencionaste:

t <- Sys.time()
dat[,First_month := apply(.SD,1,function(x) 
colnames(.SD)[min(which(!is.na(x)))])]
dat[,Value_First_month := apply(.SD,1,function(x) x[min(which(!is.na(x)))])]
difftime( Sys.time(), t)

Time difference of 3.478778 secs


- Mensaje original -
De: "Javier Villacampa González" 
Para: "R ayuda" 
Enviados: Jueves, 27 de Octubre 2016 13:43:19
Asunto: [R-es] Encontrar la primera columna no NA

Imaginemos que tenemos una matriz con datos temporales por sujetos.
Pongamos que numero de veces que ha jugado una carta en un juego online. Y
que quiero saber cuantas veces jugo la carta el primer mes que estuvo en el
juego.

Pero claro mi matriz guarda los datos temporalmente de tal manera que:

# data.table( Enero = c( 1, 4, NA , NA , NA) , Febrero = c( 2, 6, 1, NA, NA
) , Marzo = c( 8,6,7,3, NA) ,  Abril = c( NA, 15, 5, 6,6 ))
#Enero Febrero Marzo Abril
# 1: 1   2 8NA
# 2: 4   6 615
# 3:NA   1 7 5
# 4:NA  NA 3 6
# 5:NA  NANA 6
# Suponiendo que cada fila es un jugador
# En este caso la solucion debería ser
# 1 para el primero que empezó en Enero
# 4 para el segundo jugador  que empezó en Enero
# 1 para el tercero  que empezó en Febrero
# 3 Para el cuarto  que empezó en Marzo
# 6 para el quinto  que empezó en Abril


A alguno se os ocurre una solucion más eficiente que la siguiente. Esto
seguro que con data table o dplyr se puede. Ya he quitados los pipes que
facilitan la lectura pero que no se llevan bien con data.table. Pero estoy
seguro que se puede mejorar más.

#===
# Como ejemplo de codigo
#===
# S Primera solucion --
# First not NA colum per subject
library(data.table)
library(dplyr)
set.seed(123456)
numero <- 1e5
dat <-
  data.table( Uno  = sample( c(runif(numero) , rep(NA , numero /2e0  )),
size = numero ) ,
dos= sample( c(runif(numero) , rep(NA , numero /1e1  )),
size = numero ) ,
tres   = sample( c(runif(numero) , rep(NA , numero /2e1 )) ,
size = numero ) ,
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 1:N_for){
  x <- dat[  First_month == j,  j,  with = FALSE]
  dat[ First_month == j , Value_First_month := x ]
}

dat %>%  print
# dat %>%  summary

cat( "===\n", difftime( Sys.time(), t, units =
"min") , " minutos que cuesta \n===\n" )
beepr::beep(3)
# E Primera solucion --




# S comparativa ---
library(microbenchmark)
N <- 1e2
tabla <-
  microbenchmark(
JVG_dplyr ={  dat %>%
apply( MARGIN = 1, FUN =
 function(x){
   which( !is.na(x)  ) %>%  min( na.rm = TRUE ) %>%
return()
   }
)
},
JVG ={
apply(X = dat,  MARGIN = 1, FUN =
 function(x){
   return(   min(  which( !is.na(x)  ),  na.rm = TRUE ) )
 }
)
},
times = N, unit = "s")

tabla %>%  print
beepr::beep(3)

# Unit: seconds
#   exprminlq   mean medianuq   max
neval
# JVG_dplyr 21.2321152 22.233428 22.9575357 22.5701781 23.32
26.64273010
# JVG0.7628928  0.843067  0.9260389  0.8495834  1.027036
1.29586810
# E comparativa ---

--

[[alternative HTML version deleted]]

___
R-help-es mailing list
R-help-es@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-help-es

___
R-help-es mailing list
R-help-es@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-help-es


Re: [R] [FORGED] [FORGED] lattice: control panel extent on device

2016-10-27 Thread Ben Tupper
Hi,

I had not noticed the difference, but now that I can see them side-by-side it's 
obvious.  I see that I shouldn't have taken out those modifications you had 
originally set up.  They were sort of like extra those extra parts you find 
after assembling a new gizmo - "Nah, I don't need those things."  Oops!

I just realized that I was calling the alignment vertical (because the plots 
are over-under), but you referred to the alignment as horizontal which sounds 
'righter'.  I should challenge myself to do the same for vertical alignment for 
side-by-side plots.  If I get to it I'll post the results.

Thanks, again, for your time and help.

Cheers,
Ben


> On Oct 26, 2016, at 3:13 PM, Paul Murrell  wrote:
> 
> Hi
> 
> I think your plots are not *quite* horizontally aligned (because of 
> differences in the lengths of y-axis labels).  Here is a slight modification 
> that messes with the labels (but at least not manually) to get things exact 
> ...
> 
> valign_lattice <- function(x) {
> 
>if (inherits(x, "trellis")) x <- list(x)
> 
>if (!all(sapply(x, inherits, 'trellis')))
>stop("all elements of x must inherit from trellis class")
> 
>nx <- length(x)
>names(x) <- LETTERS[1:nx]
>h1 <- 1/nx
>y0 <- seq(from = 0, to = 1 - h1, length = nx)
>n <- 1
>grid.newpage()
>pushViewport(viewport(y=y0[n], height=h1, just="bottom"))
># Force identical widths where we can
>layout.widths <- lattice.options("layout.widths")[[1]]
>layout.widths$ylab <- list(x=1, units="cm", data=NULL)
>layout.widths$panel <- list(x=1, units="null", data=NULL)
>layout.widths$key.right <- list(x=1, units="cm", data=NULL)
>lattice.options(layout.widths=layout.widths)
># Force (width of) left axis labels to be the same
>yrange <- x[[n]]$y.limits
>yticks <- axisTicks(yrange, FALSE)
>x[[n]] <- update(x[[n]],
> scales=list(y=list(at=yticks,
>labels=rep(" ", length(yticks)
>prefix <- LETTERS[n]
>print(x[[n]], newpage=FALSE, prefix=prefix)
>downViewport(paste0(prefix,".panel.1.1.off.vp"))
># Draw proper left axis labels
>grid.text(yticks, x=unit(0, "npc") - unit(1, "lines"),
>  y=unit(yticks, "native"), just="right",
>  gp=gpar(cex=.8))
># Determine width of levelplot panel
>border <- grid.get("border", grep=TRUE)
>width <- convertWidth(border$width, "in", valueOnly=TRUE)
>xscale <- current.viewport()$xscale
>upViewport(0)
> 
>if (nx > 1){
>for (n in 2:nx){
>pushViewport(viewport(y=y0[n], height=h1, just="bottom"))
># Force identical widths where we can
>layout.widths$ylab <- list(x=1, units="cm", data=NULL)
>layout.widths$panel <- list(x=width, units="in", data=NULL)
>layout.widths$key.right <- list(x=1, units="cm", data=NULL)
>lattice.options(layout.widths=layout.widths)
>x[[n]] <- update(x[[n]], xlim = xscale)
># Force (width of) left axis labels to be the same
>yrange <- x[[n]]$y.limits
>yticks <- axisTicks(yrange, FALSE)
>x[[n]] <- update(x[[n]],
> scales=list(y=list(at=yticks,
>labels=rep(" ",
> length(yticks)
>prefix <- LETTERS[n]
>print(x[[n]], newpage=FALSE, prefix=prefix)
>downViewport(paste0(prefix,".panel.1.1.off.vp"))
># Draw proper left axis labels
>grid.text(yticks, x=unit(0, "npc") - unit(1, "lines"),
>  y=unit(yticks, "native"), just="right",
>  gp=gpar(cex=.8))
>upViewport(0)
>} #n-loop
>}
> }
> 
> Paul
> 
> On 27/10/16 04:21, Ben Tupper wrote:
>> Hi,
>> 
>> The following encapsulates what I hoped for using Paul's method.  The
>> function accepts one or more trellis class objects and aligns them
>> vertically.  I think I have automated most of the manual fiddling.
>> Depending upon your graphics device you may need to fiddle with the
>> aspect of the levelplot as I did below.  There remains a good deal of
>> vertical white space but it is fine for my purposes as I only need
>> two objects aligned where it looks OK.
>> 
>> I couldn't get Richard's simplified steps to work - I'm still
>> noodling that out but the simplicity is very enticing.
>> 
>> Thanks again for the all the suggestions! Ben
>> 
>>  START library(lattice) library(grid)
>> 
>> #' Vertically align one or more trellis class objects. #' #' Objects
>> are plotted in order from bottom up and all are restricted to the #'
>> horizontal extent across the device and to the data range of that of
>> the #' first object. #' #' @param x a list of one or more trellis
>> class objects valign_lattice <- function(x) {
>> 
>> if (inherits(x, "trellis")) x <- list(x)
>> 
>> if (!all(sapply(x, inherits, 

Re: [R] age old problem with rJava

2016-10-27 Thread Jeff Newmiller
The very act of using sudo for this kind of activity creates files that you can 
only access by using sudo (bad permissions), thereby perpetuating your 
difficulties. You should be able to limit yourself to only using sudo for 
installing OS packages (apt-get) which is designed to yield appropriate file 
permissions for normal use. 

Resolving such gordian knots in the operating system is off topic here, but I 
would recommend uninstalling R and your ~/R directory and the java runtime and 
then using the Ubuntu-specific instructions for setting up R that are posted on 
CRAN and avoid running R with sudo. Only use sudo with apt-get and use a local 
user-specific R library (~/R) so you don't have to use sudo to install R 
packages. If you need a system-wide installation then you need to get help in a 
more OS-specific forum... perhaps R-sig-debian.
-- 
Sent from my phone. Please excuse my brevity.

On October 27, 2016 6:42:59 AM CDT, Jim Maas  wrote:
>I've installed oracle java 8, at least think I have and tried many
>things
>but still getting this error.  For some reason if I run R as sudo, then
>the
>library rJava loads just fine, but not as user.  Any suggestions most
>welcome.
>
>Ubuntu 16.04 linux, R 3.3.1 64-bit
>
>Thanks
>
>J
>
>
>> library(rJava)
>Error : .onLoad failed in loadNamespace() for 'rJava', details:
>  call: dyn.load(file, DLLpath = DLLpath, ...)
>  error: unable to load shared object
>'/usr/local/lib/R/site-library/rJava/libs/rJava.so':
>  libjvm.so: cannot open shared object file: No such file or directory
>Error: package or namespace load failed for ‘rJava’
>
>
>-- 
>Jim Maas
>
>   [[alternative HTML version deleted]]
>
>__
>R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>https://stat.ethz.ch/mailman/listinfo/r-help
>PLEASE do read the posting guide
>http://www.R-project.org/posting-guide.html
>and provide commented, minimal, self-contained, reproducible code.

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

[R] age old problem with rJava

2016-10-27 Thread Jim Maas
I've installed oracle java 8, at least think I have and tried many things
but still getting this error.  For some reason if I run R as sudo, then the
library rJava loads just fine, but not as user.  Any suggestions most
welcome.

Ubuntu 16.04 linux, R 3.3.1 64-bit

Thanks

J


> library(rJava)
Error : .onLoad failed in loadNamespace() for 'rJava', details:
  call: dyn.load(file, DLLpath = DLLpath, ...)
  error: unable to load shared object
'/usr/local/lib/R/site-library/rJava/libs/rJava.so':
  libjvm.so: cannot open shared object file: No such file or directory
Error: package or namespace load failed for ‘rJava’


-- 
Jim Maas

[[alternative HTML version deleted]]

__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

[R-es] Encontrar la primera columna no NA

2016-10-27 Thread Javier Villacampa González
Imaginemos que tenemos una matriz con datos temporales por sujetos.
Pongamos que numero de veces que ha jugado una carta en un juego online. Y
que quiero saber cuantas veces jugo la carta el primer mes que estuvo en el
juego.

Pero claro mi matriz guarda los datos temporalmente de tal manera que:

# data.table( Enero = c( 1, 4, NA , NA , NA) , Febrero = c( 2, 6, 1, NA, NA
) , Marzo = c( 8,6,7,3, NA) ,  Abril = c( NA, 15, 5, 6,6 ))
#Enero Febrero Marzo Abril
# 1: 1   2 8NA
# 2: 4   6 615
# 3:NA   1 7 5
# 4:NA  NA 3 6
# 5:NA  NANA 6
# Suponiendo que cada fila es un jugador
# En este caso la solucion debería ser
# 1 para el primero que empezó en Enero
# 4 para el segundo jugador  que empezó en Enero
# 1 para el tercero  que empezó en Febrero
# 3 Para el cuarto  que empezó en Marzo
# 6 para el quinto  que empezó en Abril


A alguno se os ocurre una solucion más eficiente que la siguiente. Esto
seguro que con data table o dplyr se puede. Ya he quitados los pipes que
facilitan la lectura pero que no se llevan bien con data.table. Pero estoy
seguro que se puede mejorar más.

#===
# Como ejemplo de codigo
#===
# S Primera solucion --
# First not NA colum per subject
library(data.table)
library(dplyr)
set.seed(123456)
numero <- 1e5
dat <-
  data.table( Uno  = sample( c(runif(numero) , rep(NA , numero /2e0  )),
size = numero ) ,
dos= sample( c(runif(numero) , rep(NA , numero /1e1  )),
size = numero ) ,
tres   = sample( c(runif(numero) , rep(NA , numero /2e1 )) ,
size = numero ) ,
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 1:N_for){
  x <- dat[  First_month == j,  j,  with = FALSE]
  dat[ First_month == j , Value_First_month := x ]
}

dat %>%  print
# dat %>%  summary

cat( "===\n", difftime( Sys.time(), t, units =
"min") , " minutos que cuesta \n===\n" )
beepr::beep(3)
# E Primera solucion --




# S comparativa ---
library(microbenchmark)
N <- 1e2
tabla <-
  microbenchmark(
JVG_dplyr ={  dat %>%
apply( MARGIN = 1, FUN =
 function(x){
   which( !is.na(x)  ) %>%  min( na.rm = TRUE ) %>%
return()
   }
)
},
JVG ={
apply(X = dat,  MARGIN = 1, FUN =
 function(x){
   return(   min(  which( !is.na(x)  ),  na.rm = TRUE ) )
 }
)
},
times = N, unit = "s")

tabla %>%  print
beepr::beep(3)

# Unit: seconds
#   exprminlq   mean medianuq   max
neval
# JVG_dplyr 21.2321152 22.233428 22.9575357 22.5701781 23.32
26.64273010
# JVG0.7628928  0.843067  0.9260389  0.8495834  1.027036
1.29586810
# E comparativa ---

--

[[alternative HTML version deleted]]

___
R-help-es mailing list
R-help-es@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-help-es


Re: [R] interpretation of plot.svm graph

2016-10-27 Thread Indhira, Anusha
 Thanks for letting me know.Please find the image file in below link
https://github.com/anushar/bleed-analysis/blob/master/svm_classification_plot.jpeg

Thanks
-Original Message-
From: Jim Lemon [mailto:drjimle...@gmail.com]
Sent: 26 October 2016 23:37
To: Indhira, Anusha
Cc: r-help@r-project.org
Subject: Re: [R] interpretation of plot.svm graph

Hi Alily,
Your image file didn't get through to the list. Try sending a PDF image or 
perhaps providing a URL for an image stored on the internet.

Jim


On Wed, Oct 26, 2016 at 8:46 PM, Indhira, Anusha 
 wrote:
> Hi,
>
> I am trying to understand graph generated by plot.svm command. when I
> use model.svm <- svm(target.538 ~.,data = svm.data,type =
> "C-classification") plot(model.svm,svm.data,T~P,xlab="",ylab = "") I
> get attached graph.Can anyone let me know what red,bkack,green circle and 
> cross points represent? Also why are not 1-1 class represented in the graph?
>
> Thanks,
> Alily
> This e-mail (including attachments) contains contents owned by Rolls-Royce 
> plc and its subsidiaries, affiliated companies or customers and covered by 
> the laws of England and Wales, Brazil, US, or Canada (federal, state or 
> provincial). The information is intended to be confidential and may be 
> legally privileged. If you are not the intended recipient, you are hereby 
> notified that any retention, dissemination, distribution, interception or 
> copying of this communication is strictly prohibited and may subject you to 
> further legal action. Reply to the sender if you received this email by 
> accident, and then delete the email and any attachments.
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

__
This email has been scanned.
This e-mail (including attachments) contains contents owned by Rolls-Royce plc 
and its subsidiaries, affiliated companies or customers and covered by the laws 
of England and Wales, Brazil, US, or Canada (federal, state or provincial). The 
information is intended to be confidential and may be legally privileged. If 
you are not the intended recipient, you are hereby notified that any retention, 
dissemination, distribution, interception or copying of this communication is 
strictly prohibited and may subject you to further legal action. Reply to the 
sender if you received this email by accident, and then delete the email and 
any attachments.
__
R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] PROBLEM: correspondence analysis with vegan

2016-10-27 Thread PIKAL Petr
Hi Julia

Do not be too much distracted by Bert's comments. I also do not have formal 
statistical background but R usually keeps me on track as clever people 
designed its functions and made big effort in providing concise help. Together 
with this help list it can give you pretty good base for your analysis. However 
you should not expect to reach mastery overnight.

Beside what have been said, your questions to this help list should include:

- some toy data, preferably obtained by

dput(head(yourdata, 20))

result copied directly to your mail.

- the code you used for your analysis
- some description what you expected and did not obtained

However I agree with Bert that I you do not have any idea how to interpret 
results from analysis, you are asking for trouble.

Cheers
Petr


> -Original Message-
> From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Julia
> Lienert via R-help
> Sent: Wednesday, October 26, 2016 2:21 PM
> To: r-h...@stat.math.ethz.ch
> Subject: [R] PROBLEM: correspondence analysis with vegan
>
> Hello All,
>
> I’m Julia from Germany and I have a problem concerning the vegan package
> that I can’t solve on my own (after hours and hours spent searching for a
> solution). I was thrown into the topic of working with R by my professor and
> wasn’t really aware that this included working with higher statistics (since I
> studied pedagogy before and have not much basic statistical knowledge or
> knowledge of R).
>
> I need to do a correspondence analysis on a dataset of vegetation samples
> and species as a comma-separated csv file. I have the species names as row
> names. The column names indicated zonation + land use and make up the
> first row of the matrix. I set the header = TRUE.
>
> If I tried doing a CA or DCA with this dataset the warning “Error in
> rowSums(X): ‘x’ must be numeric” appeared. According to several forums, I
> then removed the first column and the CA worked and i could also apply the
> envfit function and plot it.
>
> Now here comes my problem and question:
>
> when I plotted the arrows { plot(ef, p.max = 0.1) }, I got arrows labeled with
> species in my ordination plot. But instead I would need the column that
> indicates the zonation/land use (the first column) which I had to remove in
> order for the CA/ DCA to work. Is there any way that I can incorporate the
> zonation/ land use column as environmental vector after I did the whole CA/
> DCA? Or is there any way for me to do a CA/ DCA without having to remove
> the first column?
>
> I might be missing something but I just started working with R and haven’t
> got the time to really work my way in from the basics. I will do that after 
> this
> project is done but for now I just hope that you can help me.
>
> Greetings,
> Julia
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-
> guide.html
> and provide commented, minimal, self-contained, reproducible code.


Tento e-mail a jakékoliv k němu připojené dokumenty jsou důvěrné a jsou určeny 
pouze jeho adresátům.
Jestliže jste obdržel(a) tento e-mail omylem, informujte laskavě neprodleně 
jeho odesílatele. Obsah tohoto emailu i s přílohami a jeho kopie vymažte ze 
svého systému.
Nejste-li zamýšleným adresátem tohoto emailu, nejste oprávněni tento email 
jakkoliv užívat, rozšiřovat, kopírovat či zveřejňovat.
Odesílatel e-mailu neodpovídá za eventuální škodu způsobenou modifikacemi či 
zpožděním přenosu e-mailu.

V případě, že je tento e-mail součástí obchodního jednání:
- vyhrazuje si odesílatel právo ukončit kdykoliv jednání o uzavření smlouvy, a 
to z jakéhokoliv důvodu i bez uvedení důvodu.
- a obsahuje-li nabídku, je adresát oprávněn nabídku bezodkladně přijmout; 
Odesílatel tohoto e-mailu (nabídky) vylučuje přijetí nabídky ze strany příjemce 
s dodatkem či odchylkou.
- trvá odesílatel na tom, že příslušná smlouva je uzavřena teprve výslovným 
dosažením shody na všech jejích náležitostech.
- odesílatel tohoto emailu informuje, že není oprávněn uzavírat za společnost 
žádné smlouvy s výjimkou případů, kdy k tomu byl písemně zmocněn nebo písemně 
pověřen a takové pověření nebo plná moc byly adresátovi tohoto emailu případně 
osobě, kterou adresát zastupuje, předloženy nebo jejich existence je adresátovi 
či osobě jím zastoupené známá.

This e-mail and any documents attached to it may be confidential and are 
intended only for its intended recipients.
If you received this e-mail by mistake, please immediately inform its sender. 
Delete the contents of this e-mail with all attachments and its copies from 
your system.
If you are not the intended recipient of this e-mail, you are not authorized to 
use, disseminate, copy or disclose this e-mail in any manner.
The sender of this e-mail shall not be liable for any possible damage caused by