Re: [R] About populating a dataframe in a loop

2017-01-06 Thread lily li
Thanks, Richard. But if the data cannot fill the constructed data frame,
will there be NA values?


On Fri, Jan 6, 2017 at 10:07 PM, Richard M. Heiberger 
wrote:

> Incrementally increasing the size of an array is not efficient in R.
> The recommended technique is to allocate as much space as you will
> need, and then fill it.
>
> > system.time({tmp <- 1:5 ; for (i in 1:1000) tmp <- rbind(tmp, 1:5)})
>user  system elapsed
>   0.011   0.000   0.011
> > dim(tmp)
> [1] 10015
> > system.time({tmp <- matrix(NA, 1001, 5); for (i in 1:1001) tmp[i,] <-
> 1:5})
>user  system elapsed
>   0.001   0.000   0.001
> > dim(tmp)
> [1] 10015
>
> On Fri, Jan 6, 2017 at 11:46 PM, lily li  wrote:
> > Hi Rui,
> >
> > Thanks for your reply. Yes, when I tried to rbind two dataframes, it
> works.
> > However, if there are more than 50, it got stuck for hours. When I tried
> to
> > terminate the process and open the csv file separately, it has only one
> > data frame. What is the problem? Thanks.
> >
> >
> > On Fri, Jan 6, 2017 at 11:12 AM, Rui Barradas 
> wrote:
> >
> >> Hello,
> >>
> >> Works with me:
> >>
> >> set.seed(6574)
> >>
> >> pre.mat = data.frame()
> >> for(i in 1:10){
> >> mat.temp = data.frame(x = rnorm(5), A = sample(LETTERS, 5, TRUE))
> >> pre.mat = rbind(pre.mat, mat.temp)
> >> }
> >>
> >> nrow(pre.mat)  # should be 50
> >>
> >>
> >> Can you give us an example that doesn't work?
> >>
> >> Rui Barradas
> >>
> >>
> >> Em 06-01-2017 18:00, lily li escreveu:
> >>
> >>> Hi R users,
> >>>
> >>> I have a question about filling a dataframe in R using a for loop.
> >>>
> >>> I created an empty dataframe first and then filled it, using the code:
> >>> pre.mat = data.frame()
> >>> for(i in 1:10){
> >>>  mat.temp = data.frame(some values filled in)
> >>>  pre.mat = rbind(pre.mat, mat.temp)
> >>> }
> >>> However, the resulted dataframe has not all the rows that I desired
> for.
> >>> What is the problem and how to solve it? Thanks.
> >>>
> >>> [[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/posti
> >>> ng-guide.html
> >>> and provide commented, minimal, self-contained, reproducible code.
> >>>
> >>>
> >
> > [[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.
>

[[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.


Re: [R] About populating a dataframe in a loop

2017-01-06 Thread jeremiah rounds
As a rule never rbind in a loop. It has O(n^2) run time because the rbind
itself can be O(n) (where n is the number of data.frames).  Instead either
put them all into a list with lapply or vector("list", length=) and then
datatable::rbindlist, do.call(rbind, thelist) or use the equivalent from
dplyr.  All of which will be much more efficient.



On Fri, Jan 6, 2017 at 8:46 PM, lily li  wrote:

> Hi Rui,
>
> Thanks for your reply. Yes, when I tried to rbind two dataframes, it works.
> However, if there are more than 50, it got stuck for hours. When I tried to
> terminate the process and open the csv file separately, it has only one
> data frame. What is the problem? Thanks.
>
>
> On Fri, Jan 6, 2017 at 11:12 AM, Rui Barradas 
> wrote:
>
> > Hello,
> >
> > Works with me:
> >
> > set.seed(6574)
> >
> > pre.mat = data.frame()
> > for(i in 1:10){
> > mat.temp = data.frame(x = rnorm(5), A = sample(LETTERS, 5, TRUE))
> > pre.mat = rbind(pre.mat, mat.temp)
> > }
> >
> > nrow(pre.mat)  # should be 50
> >
> >
> > Can you give us an example that doesn't work?
> >
> > Rui Barradas
> >
> >
> > Em 06-01-2017 18:00, lily li escreveu:
> >
> >> Hi R users,
> >>
> >> I have a question about filling a dataframe in R using a for loop.
> >>
> >> I created an empty dataframe first and then filled it, using the code:
> >> pre.mat = data.frame()
> >> for(i in 1:10){
> >>  mat.temp = data.frame(some values filled in)
> >>  pre.mat = rbind(pre.mat, mat.temp)
> >> }
> >> However, the resulted dataframe has not all the rows that I desired for.
> >> What is the problem and how to solve it? Thanks.
> >>
> >> [[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/posti
> >> ng-guide.html
> >> and provide commented, minimal, self-contained, reproducible code.
> >>
> >>
>
> [[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.
>

[[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.


Re: [R] About populating a dataframe in a loop

2017-01-06 Thread Richard M. Heiberger
Incrementally increasing the size of an array is not efficient in R.
The recommended technique is to allocate as much space as you will
need, and then fill it.

> system.time({tmp <- 1:5 ; for (i in 1:1000) tmp <- rbind(tmp, 1:5)})
   user  system elapsed
  0.011   0.000   0.011
> dim(tmp)
[1] 10015
> system.time({tmp <- matrix(NA, 1001, 5); for (i in 1:1001) tmp[i,] <- 1:5})
   user  system elapsed
  0.001   0.000   0.001
> dim(tmp)
[1] 10015

On Fri, Jan 6, 2017 at 11:46 PM, lily li  wrote:
> Hi Rui,
>
> Thanks for your reply. Yes, when I tried to rbind two dataframes, it works.
> However, if there are more than 50, it got stuck for hours. When I tried to
> terminate the process and open the csv file separately, it has only one
> data frame. What is the problem? Thanks.
>
>
> On Fri, Jan 6, 2017 at 11:12 AM, Rui Barradas  wrote:
>
>> Hello,
>>
>> Works with me:
>>
>> set.seed(6574)
>>
>> pre.mat = data.frame()
>> for(i in 1:10){
>> mat.temp = data.frame(x = rnorm(5), A = sample(LETTERS, 5, TRUE))
>> pre.mat = rbind(pre.mat, mat.temp)
>> }
>>
>> nrow(pre.mat)  # should be 50
>>
>>
>> Can you give us an example that doesn't work?
>>
>> Rui Barradas
>>
>>
>> Em 06-01-2017 18:00, lily li escreveu:
>>
>>> Hi R users,
>>>
>>> I have a question about filling a dataframe in R using a for loop.
>>>
>>> I created an empty dataframe first and then filled it, using the code:
>>> pre.mat = data.frame()
>>> for(i in 1:10){
>>>  mat.temp = data.frame(some values filled in)
>>>  pre.mat = rbind(pre.mat, mat.temp)
>>> }
>>> However, the resulted dataframe has not all the rows that I desired for.
>>> What is the problem and how to solve it? Thanks.
>>>
>>> [[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/posti
>>> ng-guide.html
>>> and provide commented, minimal, self-contained, reproducible code.
>>>
>>>
>
> [[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.


Re: [R] About populating a dataframe in a loop

2017-01-06 Thread lily li
Hi Rui,

Thanks for your reply. Yes, when I tried to rbind two dataframes, it works.
However, if there are more than 50, it got stuck for hours. When I tried to
terminate the process and open the csv file separately, it has only one
data frame. What is the problem? Thanks.


On Fri, Jan 6, 2017 at 11:12 AM, Rui Barradas  wrote:

> Hello,
>
> Works with me:
>
> set.seed(6574)
>
> pre.mat = data.frame()
> for(i in 1:10){
> mat.temp = data.frame(x = rnorm(5), A = sample(LETTERS, 5, TRUE))
> pre.mat = rbind(pre.mat, mat.temp)
> }
>
> nrow(pre.mat)  # should be 50
>
>
> Can you give us an example that doesn't work?
>
> Rui Barradas
>
>
> Em 06-01-2017 18:00, lily li escreveu:
>
>> Hi R users,
>>
>> I have a question about filling a dataframe in R using a for loop.
>>
>> I created an empty dataframe first and then filled it, using the code:
>> pre.mat = data.frame()
>> for(i in 1:10){
>>  mat.temp = data.frame(some values filled in)
>>  pre.mat = rbind(pre.mat, mat.temp)
>> }
>> However, the resulted dataframe has not all the rows that I desired for.
>> What is the problem and how to solve it? Thanks.
>>
>> [[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/posti
>> ng-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
>>

[[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] que tal comunidad, una pregunta del paquete data.table

2017-01-06 Thread patricio fuenmayor
Hola.
Esta es una manera:

require(data.table)
dt <-
data.table(v1=letters[1:30],v2=round(runif(30,max=20)),v3=rep(c("x","y","z"),10))
dt[unlist(dt[,.I[which.max(v2)],by=v3,drop=TRUE][,2])]

Saludos.

[[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] Problem with IRkernel Installation Solved - Instructions on how to Solve it

2017-01-06 Thread Ista Zahn
On Jan 6, 2017 2:11 PM, "Paul Bernal"  wrote:

Ista,

If you do not appreciate it or do not find it useful, just discard the
message.

It's not about me. My concern is for the people you potentially send on a
wild goose chase when all they really need to do is follow the IRkernel
documentation.

I tried several things and this is what worked for me. If you have another
solution or a better solution let me know.


A better solution is to follow the IRkernel installation instructions. If
it doesn't work ask for help by describing exactly what you did and exactly
what happened.

Best,
Ista


Regards,

Paul

2017-01-06 13:00 GMT-05:00 Ista Zahn :

> On Fri, Jan 6, 2017 at 8:43 AM, Paul Bernal 
> wrote:
> > Dear friends,
> >
> > Great news! I was able to install the IRkernel successfully and I am now
> > able to create R notebooks in Jupyter.
>
> Congratulations.
>
>  Just in case anybody out there is
> > struggling with this too, here is what I did (I have Windows 8, but it
> will
> > probably work for Mac OS X as well):
> >
> > 1-Go to the page https://irkernel.github.io/installation
> > 2-Open the R console (I have R version 3.3.2)
> > 3-Go to the step where it says "Installing via supplied binary packages
> > (default on Windows + Mac OS X)
> > 4-Instead of installing all the packages using one single command as
> > suggested in the installation instructions, go to the R console and
> install
> > all of the packages one by one, as follows
> >  >install.packages('repr')
> >  >install.packages('IRdisplay')
> >  >install.packages('evaluate')
> >  >install.packages('crayon')
> >  >install.packages('pbdZMQ')
> >  >install.packages('devtools')
> >  >install.packages('uuid')
> >  >install.packages('digest')
>
> This can hardly make any difference.
>
> install.packages(c('repr', 'IRdisplay', 'evaluate', 'crayon',
> 'pbdZMQ', 'devtools', 'uuid', 'digest'))
>
> is fine.
>
> > 5-Connect to a CRAN mirror and select install packages, look for the
> > package githubinstall and clic on it to install it
>
> Why?
>
> > 6-Start loading each one of the packages installed like this:
> >  >library("repr")
> >  >library("IRdisplay")
> >  >library("evaluate")
> >  >library("crayon")
> >  >library("pbdZMQ")
> >  >library("devtools")
> >  >library("uuid")
> >  >library("digest")
> >  >library("githubinstall")
>
> Attaching all these packages is not needed. The githubinstall package
> is not needed at all.
>
> > 7-After this you have to update jsonlite which is a dependencie of
> package
> > githubinstall, you update jsonlite using the following command:
> >  >update.packages('jsonlite')'
>
> Also not needed, as githubinstall is not needed.
>
> > 8-After this, you have to type the following commands:
> >  >library(httr)
> >  >set_config(use_proxy(url="the required IP", port=8080, username="your
> > network user", password="the password you use to unlock your computer"))
> >  >#you can get the required IP going to the command prompt and using the
> > command ping
> >  >#port has to be 8080
>
> Maybe something like this is needed if you are behind a firewall, I
> don't know. But none of that is generally needed.
>
> > 9-type use the command:
> >  >devtools::install_github('IRkernel/IRkernel')
> > 10-Last but not least, type the following command:
> >  >IRkernel::installspec()
> >
> > If you follow this instructions you should be able to install the
> IRkernel
> > successfully and start writing R notebooks in Jupyter.
> >
> > Hope this helps,
>
> I suspect it will confuse more than help unfortunately.
>
> Best,
> Ista
>
> >
> > [[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/posti
> ng-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
>

[[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.


Re: [R] Problem with IRkernel Installation Solved - Instructions on how to Solve it

2017-01-06 Thread Paul Bernal
Ista,

If you do not appreciate it or do not find it useful, just discard the
message. I tried several things and this is what worked for me. If you have
another solution or a better solution let me know.

Regards,

Paul

2017-01-06 13:00 GMT-05:00 Ista Zahn :

> On Fri, Jan 6, 2017 at 8:43 AM, Paul Bernal 
> wrote:
> > Dear friends,
> >
> > Great news! I was able to install the IRkernel successfully and I am now
> > able to create R notebooks in Jupyter.
>
> Congratulations.
>
>  Just in case anybody out there is
> > struggling with this too, here is what I did (I have Windows 8, but it
> will
> > probably work for Mac OS X as well):
> >
> > 1-Go to the page https://irkernel.github.io/installation
> > 2-Open the R console (I have R version 3.3.2)
> > 3-Go to the step where it says "Installing via supplied binary packages
> > (default on Windows + Mac OS X)
> > 4-Instead of installing all the packages using one single command as
> > suggested in the installation instructions, go to the R console and
> install
> > all of the packages one by one, as follows
> >  >install.packages('repr')
> >  >install.packages('IRdisplay')
> >  >install.packages('evaluate')
> >  >install.packages('crayon')
> >  >install.packages('pbdZMQ')
> >  >install.packages('devtools')
> >  >install.packages('uuid')
> >  >install.packages('digest')
>
> This can hardly make any difference.
>
> install.packages(c('repr', 'IRdisplay', 'evaluate', 'crayon',
> 'pbdZMQ', 'devtools', 'uuid', 'digest'))
>
> is fine.
>
> > 5-Connect to a CRAN mirror and select install packages, look for the
> > package githubinstall and clic on it to install it
>
> Why?
>
> > 6-Start loading each one of the packages installed like this:
> >  >library("repr")
> >  >library("IRdisplay")
> >  >library("evaluate")
> >  >library("crayon")
> >  >library("pbdZMQ")
> >  >library("devtools")
> >  >library("uuid")
> >  >library("digest")
> >  >library("githubinstall")
>
> Attaching all these packages is not needed. The githubinstall package
> is not needed at all.
>
> > 7-After this you have to update jsonlite which is a dependencie of
> package
> > githubinstall, you update jsonlite using the following command:
> >  >update.packages('jsonlite')'
>
> Also not needed, as githubinstall is not needed.
>
> > 8-After this, you have to type the following commands:
> >  >library(httr)
> >  >set_config(use_proxy(url="the required IP", port=8080, username="your
> > network user", password="the password you use to unlock your computer"))
> >  >#you can get the required IP going to the command prompt and using the
> > command ping
> >  >#port has to be 8080
>
> Maybe something like this is needed if you are behind a firewall, I
> don't know. But none of that is generally needed.
>
> > 9-type use the command:
> >  >devtools::install_github('IRkernel/IRkernel')
> > 10-Last but not least, type the following command:
> >  >IRkernel::installspec()
> >
> > If you follow this instructions you should be able to install the
> IRkernel
> > successfully and start writing R notebooks in Jupyter.
> >
> > Hope this helps,
>
> I suspect it will confuse more than help unfortunately.
>
> Best,
> Ista
>
> >
> > [[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.
>

[[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.


Re: [R-es] que tal comunidad, una pregunta del paquete data.table

2017-01-06 Thread eric

Muchas gracias Carlos, Carlos y Javier, vamos a probar las opciones.

Saludos, Eric.






On 01/06/2017 12:38 PM, Carlos J. Gil Bellosta  wrote:

Lo que quieres es un sort y, luego, un tail. Abundando en el ejemplo de
Carlos Ortega,

library(data.table)
set.seed(22)

tmp <- data.table(x = rnorm(100), y = rnorm(100), z = sample(1:5, 100,
replace = TRUE))

setkeyv(tmp, c("z", "y"))
tmp[, tail(.SD, 1), by=z]

Así puedes sacar los N mayores, etc.

Un saludo,

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



El 6 de enero de 2017, 4:38, eric > escribió:

si se tiene un data.table (DT), supongamos de 100 filas por 3
columnas de datos numericos, como puedo hacer para obtener el
correspondiente valor de la columna 1 si busco, por ejemplo, el
maximo de la columna 2 agrupado por la columna 3 ?

para buscar el maximo de la columna 2 escribo.

DT[ , max(c2), by=c3 ]

muchas gracias,

saludos, eric.




--
Forest Engineer
Master in Environmental and Natural Resource Economics
Ph.D. student in Sciences of Natural Resources at La Frontera University
Member in AguaDeTemu2030, citizen movement for Temuco with green
city standards for living

Nota: Las tildes se han omitido para asegurar compatibilidad con
algunos lectores de correo.

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





--
Forest Engineer
Master in Environmental and Natural Resource Economics
Ph.D. student in Sciences of Natural Resources at La Frontera University
Member in AguaDeTemu2030, citizen movement for Temuco with green city 
standards for living


Nota: Las tildes se han omitido para asegurar compatibilidad con algunos 
lectores de correo.


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


Re: [R] About populating a dataframe in a loop

2017-01-06 Thread Rui Barradas

Hello,

Works with me:

set.seed(6574)

pre.mat = data.frame()
for(i in 1:10){
mat.temp = data.frame(x = rnorm(5), A = sample(LETTERS, 5, TRUE))
pre.mat = rbind(pre.mat, mat.temp)
}

nrow(pre.mat)  # should be 50


Can you give us an example that doesn't work?

Rui Barradas

Em 06-01-2017 18:00, lily li escreveu:

Hi R users,

I have a question about filling a dataframe in R using a for loop.

I created an empty dataframe first and then filled it, using the code:
pre.mat = data.frame()
for(i in 1:10){
 mat.temp = data.frame(some values filled in)
 pre.mat = rbind(pre.mat, mat.temp)
}
However, the resulted dataframe has not all the rows that I desired for.
What is the problem and how to solve it? Thanks.

[[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.


Re: [R] Problem with IRkernel Installation Solved - Instructions on how to Solve it

2017-01-06 Thread Ista Zahn
On Fri, Jan 6, 2017 at 8:43 AM, Paul Bernal  wrote:
> Dear friends,
>
> Great news! I was able to install the IRkernel successfully and I am now
> able to create R notebooks in Jupyter.

Congratulations.

 Just in case anybody out there is
> struggling with this too, here is what I did (I have Windows 8, but it will
> probably work for Mac OS X as well):
>
> 1-Go to the page https://irkernel.github.io/installation
> 2-Open the R console (I have R version 3.3.2)
> 3-Go to the step where it says "Installing via supplied binary packages
> (default on Windows + Mac OS X)
> 4-Instead of installing all the packages using one single command as
> suggested in the installation instructions, go to the R console and install
> all of the packages one by one, as follows
>  >install.packages('repr')
>  >install.packages('IRdisplay')
>  >install.packages('evaluate')
>  >install.packages('crayon')
>  >install.packages('pbdZMQ')
>  >install.packages('devtools')
>  >install.packages('uuid')
>  >install.packages('digest')

This can hardly make any difference.

install.packages(c('repr', 'IRdisplay', 'evaluate', 'crayon',
'pbdZMQ', 'devtools', 'uuid', 'digest'))

is fine.

> 5-Connect to a CRAN mirror and select install packages, look for the
> package githubinstall and clic on it to install it

Why?

> 6-Start loading each one of the packages installed like this:
>  >library("repr")
>  >library("IRdisplay")
>  >library("evaluate")
>  >library("crayon")
>  >library("pbdZMQ")
>  >library("devtools")
>  >library("uuid")
>  >library("digest")
>  >library("githubinstall")

Attaching all these packages is not needed. The githubinstall package
is not needed at all.

> 7-After this you have to update jsonlite which is a dependencie of package
> githubinstall, you update jsonlite using the following command:
>  >update.packages('jsonlite')'

Also not needed, as githubinstall is not needed.

> 8-After this, you have to type the following commands:
>  >library(httr)
>  >set_config(use_proxy(url="the required IP", port=8080, username="your
> network user", password="the password you use to unlock your computer"))
>  >#you can get the required IP going to the command prompt and using the
> command ping
>  >#port has to be 8080

Maybe something like this is needed if you are behind a firewall, I
don't know. But none of that is generally needed.

> 9-type use the command:
>  >devtools::install_github('IRkernel/IRkernel')
> 10-Last but not least, type the following command:
>  >IRkernel::installspec()
>
> If you follow this instructions you should be able to install the IRkernel
> successfully and start writing R notebooks in Jupyter.
>
> Hope this helps,

I suspect it will confuse more than help unfortunately.

Best,
Ista

>
> [[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] About populating a dataframe in a loop

2017-01-06 Thread lily li
Hi R users,

I have a question about filling a dataframe in R using a for loop.

I created an empty dataframe first and then filled it, using the code:
pre.mat = data.frame()
for(i in 1:10){
mat.temp = data.frame(some values filled in)
pre.mat = rbind(pre.mat, mat.temp)
}
However, the resulted dataframe has not all the rows that I desired for.
What is the problem and how to solve it? Thanks.

[[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.


Re: [R] extract minimal variables from model

2017-01-06 Thread Marc Schwartz

> On Jan 6, 2017, at 11:03 AM, Jacob Wegelin  wrote:
> 
> Given any regression model, created for instance by lm, lme, lmer, or rqs, 
> such as
> 
> z1<-lm(weight~poly(Time,2), data=ChickWeight)
> 
> I would like a general way to obtain only those variables used for the model. 
>  In the current example, this "minimal data frame" would consist of the 
> "weight" and "Time" variables and none of the other columns of ChickWeight.
> 
> (Motivation: Sometimes the data frame contains thousands of variables which 
> are not used in the current regression, and I do not want to keep copying and 
> propagating them.)
> 
> The "model" component of the regression object doesn't serve this purpose:
> 
>> head(z1$model)
>  weight poly(Time, 2).1 poly(Time, 2).2
> 1 42-0.066020938 0.072002235
> 2 51-0.053701293 0.031099018
> 3 59-0.041381647-0.001334588
> 4 64-0.029062001-0.025298582
> 5 76-0.016742356-0.040792965
> 6 93-0.004422710-0.047817737
> 
> The following awkward workaround seems to do it when variable names contain 
> only "word characters" as defined by regex:
> 
> minimalvariablesfrommodel20161120 <-function(object, originaldata){
> # stopifnot(!missing(originaldata))
> stopifnot(!missing(object))
> intersect(
>   unique(unlist(strsplit(format(object$call$formula), split="\\W", 
> perl=TRUE)))
>   , names(originaldata)
>   )
> }
> 
>> minimalvariablesfrommodel20161120(z1, ChickWeight)
> [1] "weight" "Time" 
>> 
> 
> But if a variable has a space in its name, my workaround fails:
> 
>> ChickWeight$"dog tail"<-ChickWeight$Time
>> z1<-lm(weight~poly(`dog tail`,2), data=ChickWeight)
>> head(z1$model)
>  weight poly(`dog tail`, 2).1 poly(`dog tail`, 2).2
> 1 42  -0.066020938   0.072002235
> 2 51  -0.053701293   0.031099018
> 3 59  -0.041381647  -0.001334588
> 4 64  -0.029062001  -0.025298582
> 5 76  -0.016742356  -0.040792965
> 6 93  -0.004422710  -0.047817737
>> minimalvariablesfrommodel20161120(z1, ChickWeight)
> [1] "weight"
>> 
> 
> Is there a more elegant, and hence more reliable, approach?
> 
> Thanks
> 
> Jacob A. Wegelin


Jacob,

In general, if you have a model object 'm', you can use the following syntax:

  all.vars(terms(m))

See ?terms and ?all.vars, the latter also includes all.names().

Regards,

Marc Schwartz

__
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] extract minimal variables from model

2017-01-06 Thread Jacob Wegelin

Given any regression model, created for instance by lm, lme, lmer, or rqs, such 
as

z1<-lm(weight~poly(Time,2), data=ChickWeight)

I would like a general way to obtain only those variables used for the model.  In the current example, this 
"minimal data frame" would consist of the "weight" and "Time" variables and 
none of the other columns of ChickWeight.

(Motivation: Sometimes the data frame contains thousands of variables which are 
not used in the current regression, and I do not want to keep copying and 
propagating them.)

The "model" component of the regression object doesn't serve this purpose:


head(z1$model)

  weight poly(Time, 2).1 poly(Time, 2).2
1 42-0.066020938 0.072002235
2 51-0.053701293 0.031099018
3 59-0.041381647-0.001334588
4 64-0.029062001-0.025298582
5 76-0.016742356-0.040792965
6 93-0.004422710-0.047817737

The following awkward workaround seems to do it when variable names contain only 
"word characters" as defined by regex:

minimalvariablesfrommodel20161120 <-function(object, originaldata){
# 
stopifnot(!missing(originaldata))

stopifnot(!missing(object))
intersect(
unique(unlist(strsplit(format(object$call$formula), split="\\W", 
perl=TRUE)))
, names(originaldata)
)
}


minimalvariablesfrommodel20161120(z1, ChickWeight)
[1] "weight" "Time" 




But if a variable has a space in its name, my workaround fails:


ChickWeight$"dog tail"<-ChickWeight$Time
z1<-lm(weight~poly(`dog tail`,2), data=ChickWeight)
head(z1$model)

  weight poly(`dog tail`, 2).1 poly(`dog tail`, 2).2
1 42  -0.066020938   0.072002235
2 51  -0.053701293   0.031099018
3 59  -0.041381647  -0.001334588
4 64  -0.029062001  -0.025298582
5 76  -0.016742356  -0.040792965
6 93  -0.004422710  -0.047817737

minimalvariablesfrommodel20161120(z1, ChickWeight)

[1] "weight"




Is there a more elegant, and hence more reliable, approach?

Thanks

Jacob A. Wegelin
Assistant Professor
C. Kenneth and Dianne Wright Center for Clinical and Translational Research
Department of Biostatistics
Virginia Commonwealth University
830 E. Main St., Seventh Floor
P. O. Box 980032
Richmond VA 23298-0032
U.S.A. 
URL: http://www.people.vcu.edu/~jwegelin


__
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] purrr::map and xml2:: read_xml

2017-01-06 Thread Ulrik Stervbo
Hi Maicel,

I'm guessing that B works on 50 files, and that A fails because there is no
function called 'read_xmlmap'. If the function that you map work well,
removing 'dplyr::sample_n(50)' from 'B' should solve the problem.

If that is not the case, we need a bit more information.

HTH
Ulrik

On Fri, 6 Jan 2017 at 17:08  wrote:

> Hi List, I am trying to extract the key words from 1403 papers in xml
> format. I programmed such codes but they do not work but they only do
> with the modification showed below. But that variation is not the one
> I need because the 1403 xml files do not match to those in my folder.
> Could you please tell me where are the mistakes in the codes list (A
> or B) to help me to correct them? The data frame columns are an id and
> the paths.
>
> A-Does not work, but it is the one I need.
>
> keyword <-
>muestra %>%
>select(path) %>%
>read_xmlmap(.f = function(x) { read_xml(x) %>%
> xml_find_all( ".//kwd") %>%
> xml_text(trim=T) })
>
> B-It works but only with a small number of papers.
>
> keyword <-
>muestra %>%
>select(path) %>%
> dplyr::sample_n(50) %>%
> unlist() %>%
>map(.f = function(x) { read_xml(x) %>%
> xml_find_all( ".//kwd") %>%
> xml_text(trim=T) })
>
> Thank you,
> Maicel Monzon MD, PHD
>
>
> 
>
>
>
>
> --
> 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/
>
> __
> 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.
>

[[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] purrr::map and xml2:: read_xml

2017-01-06 Thread maicel
Hi List, I am trying to extract the key words from 1403 papers in xml  
format. I programmed such codes but they do not work but they only do  
with the modification showed below. But that variation is not the one  
I need because the 1403 xml files do not match to those in my folder.  
Could you please tell me where are the mistakes in the codes list (A  
or B) to help me to correct them? The data frame columns are an id and  
the paths.


A-Does not work, but it is the one I need.

keyword <-
  muestra %>%
  select(path) %>%
  read_xmlmap(.f = function(x) { read_xml(x) %>%
   xml_find_all( ".//kwd") %>%
   xml_text(trim=T) })

B-It works but only with a small number of papers.

keyword <-
  muestra %>%
  select(path) %>%
   dplyr::sample_n(50) %>%
   unlist() %>%
  map(.f = function(x) { read_xml(x) %>%
   xml_find_all( ".//kwd") %>%
   xml_text(trim=T) })

Thank you,
Maicel Monzon MD, PHD







--
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/

__
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] que tal comunidad, una pregunta del paquete data.table

2017-01-06 Thread Carlos J. Gil Bellosta
Lo que quieres es un sort y, luego, un tail. Abundando en el ejemplo de
Carlos Ortega,

library(data.table)
set.seed(22)

tmp <- data.table(x = rnorm(100), y = rnorm(100), z = sample(1:5, 100,
replace = TRUE))

setkeyv(tmp, c("z", "y"))
tmp[, tail(.SD, 1), by=z]

Así puedes sacar los N mayores, etc.

Un saludo,

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



El 6 de enero de 2017, 4:38, eric  escribió:

> si se tiene un data.table (DT), supongamos de 100 filas por 3 columnas de
> datos numericos, como puedo hacer para obtener el correspondiente valor de
> la columna 1 si busco, por ejemplo, el maximo de la columna 2 agrupado por
> la columna 3 ?
>
> para buscar el maximo de la columna 2 escribo.
>
> DT[ , max(c2), by=c3 ]
>
> muchas gracias,
>
> saludos, eric.
>
>
>
>
> --
> Forest Engineer
> Master in Environmental and Natural Resource Economics
> Ph.D. student in Sciences of Natural Resources at La Frontera University
> Member in AguaDeTemu2030, citizen movement for Temuco with green city
> standards for living
>
> Nota: Las tildes se han omitido para asegurar compatibilidad con algunos
> lectores de correo.
>
> ___
> 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] testing whether clusters in a PCA plot are significantly different from one another

2017-01-06 Thread Marchesi, Julian
many thanks david for such a swift response, really appreciate your help

cheers

Julian

Julian R. Marchesi

Deputy Director and Professor of Clinical Microbiome Research at the  Centre 
for Digestive and Gut Health, Imperial College London, London W2 1NY Tel: +44 
(0)20 331 26197

and

Professor of Human Microbiome Research at the School of Biosciences, Museum 
Avenue, Cardiff University, Cardiff, CF10 3AT, Tel: +44 (0)29 208 74188, Fax: 
+44 (0)29 20874305, Mobile 07885 569144





From: David L Carlson 
Sent: 06 January 2017 15:29
To: Marchesi, Julian; r-help@r-project.org
Subject: RE: [R] testing whether clusters in a PCA plot are significantly 
different from one another

In that case you should be able to use manova where pc1 and pc2 are the 
independent (response) variables and group (Baseline, HFD+P, HFD) is the 
dependent (explanatory) variable. Something like lm(cbind(pc1, pc2)~group). 
That will give you slopes for HFD+P and HFD (difference in mean relative to 
Baseline), t-values, and p-values for each component. You can get further 
diagnostics using package candisc. But your sample size is very small so there 
may be better approaches that a statistician specializing in medical research 
could suggest.

David C

-Original Message-
From: Marchesi, Julian [mailto:j.march...@imperial.ac.uk]
Sent: Friday, January 6, 2017 9:02 AM
To: David L Carlson
Subject: Re: [R] testing whether clusters in a PCA plot are significantly 
different from one another

Dear David

The clusters are defined by the metadata which tells R where to draw the lines 
- no more no less

How would I put a P value to those clusters?

cheers

Julian

Julian R. Marchesi

Deputy Director and Professor of Clinical Microbiome Research at the  Centre 
for Digestive and Gut Health, Imperial College London, London W2 1NY Tel: +44 
(0)20 331 26197

and

Professor of Human Microbiome Research at the School of Biosciences, Museum 
Avenue, Cardiff University, Cardiff, CF10 3AT, Tel: +44 (0)29 208 74188, Fax: 
+44 (0)29 20874305, Mobile 07885 569144





From: David L Carlson 
Sent: 06 January 2017 14:26
To: Marchesi, Julian
Subject: RE: [R] testing whether clusters in a PCA plot are significantly 
different from one another

You do not say how you defined the clusters in the plot that you attached. If 
you used the variables summarized by the principal components, the answer is 
yes, they are "significantly different".

Cluster analysis creates homogeneous clusters that will almost always be 
"significantly different" using standard tests such as analysis of variance. 
BUT these tests are only meaningful when the clusters are defined independently 
of the data.


David L. Carlson
Department of Anthropology
Texas A University



-Original Message-
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Marchesi, Julian
Sent: Friday, January 6, 2017 1:43 AM
To: 'r-help@r-project.org' 
Subject: [R] testing whether clusters in a PCA plot are significantly different 
from one another

__
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.


Re: [R] testing whether clusters in a PCA plot are significantly different from one another

2017-01-06 Thread David L Carlson
In that case you should be able to use manova where pc1 and pc2 are the 
independent (response) variables and group (Baseline, HFD+P, HFD) is the 
dependent (explanatory) variable. Something like lm(cbind(pc1, pc2)~group). 
That will give you slopes for HFD+P and HFD (difference in mean relative to 
Baseline), t-values, and p-values for each component. You can get further 
diagnostics using package candisc. But your sample size is very small so there 
may be better approaches that a statistician specializing in medical research 
could suggest.

David C

-Original Message-
From: Marchesi, Julian [mailto:j.march...@imperial.ac.uk] 
Sent: Friday, January 6, 2017 9:02 AM
To: David L Carlson
Subject: Re: [R] testing whether clusters in a PCA plot are significantly 
different from one another

Dear David

The clusters are defined by the metadata which tells R where to draw the lines 
- no more no less

How would I put a P value to those clusters?

cheers

Julian

Julian R. Marchesi

Deputy Director and Professor of Clinical Microbiome Research at the  Centre 
for Digestive and Gut Health, Imperial College London, London W2 1NY Tel: +44 
(0)20 331 26197

and

Professor of Human Microbiome Research at the School of Biosciences, Museum 
Avenue, Cardiff University, Cardiff, CF10 3AT, Tel: +44 (0)29 208 74188, Fax: 
+44 (0)29 20874305, Mobile 07885 569144





From: David L Carlson 
Sent: 06 January 2017 14:26
To: Marchesi, Julian
Subject: RE: [R] testing whether clusters in a PCA plot are significantly 
different from one another

You do not say how you defined the clusters in the plot that you attached. If 
you used the variables summarized by the principal components, the answer is 
yes, they are "significantly different".

Cluster analysis creates homogeneous clusters that will almost always be 
"significantly different" using standard tests such as analysis of variance. 
BUT these tests are only meaningful when the clusters are defined independently 
of the data.


David L. Carlson
Department of Anthropology
Texas A University



-Original Message-
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Marchesi, Julian
Sent: Friday, January 6, 2017 1:43 AM
To: 'r-help@r-project.org' 
Subject: [R] testing whether clusters in a PCA plot are significantly different 
from one another

__
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.


Re: [R] Tobit Regression with unbalanced Panel Data

2017-01-06 Thread peter dalgaard

On 06 Jan 2017, at 15:08 , Vanessa Romero  wrote:

> BHHH maximisation, 150 iterations
> Return code 4: Iteration limit exceeded.
> Log-likelihood: -66915.77 on 10 Df
> 
> How can I calculate McFadden's adjusted  R2 in R?

Google gets you there soon enough (e.g., "mcfadden r2 in r tobit"). One of the 
hits point to a Stata FAQ, explaining why McF's R^2 is nonsensical for tobit 
models

> How could I reduce iteration?

Better starting values? In the absences of that, I think you want to _increase_ 
the limit, so that you are more sure that the procedure has converged. Also, a 
logSigma of -5.4 suggests that you are working with small numbers -- it 
sometimes helps to scale things by a factor of 100 or 1000.

-pd

-- 
Peter Dalgaard, Professor,
Center for Statistics, Copenhagen Business School
Solbjerg Plads 3, 2000 Frederiksberg, Denmark
Phone: (+45)38153501
Office: A 4.23
Email: pd@cbs.dk  Priv: pda...@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] Tobit Regression with unbalanced Panel Data

2017-01-06 Thread Vanessa Romero
Thank you for your answers.

I have just replaced pdata.frame with plm.data and it worked.

tobit1<- plm.data(T1, index = c("firm", "year"))

But I have two more questions, maybe someone could help:

summary(Tob)

Call:
censReg(formula = Imp ~ Bath + CEOTurnover + ChangeOCF + E +
Sales + ROE + GTA + Size, data = tobit1, method = "BHHH")

Observations:
 Total  Left-censored Uncensored Right-censored
   606469137  0

Coefficients:
  Estimate Std. errort value  Pr(> t)
(Intercept)  1.110e-03  5.648e-04  1.965   0.0494 *
Bath 7.442e-03  6.780e-03  1.098   0.2724
CEOTurnover -1.500e-03  2.742e-04 -5.472 4.45e-08 ***
ChangeOCF   -6.738e-03  1.272e-03 -5.297 1.18e-07 ***
E   -5.515e-02  5.304e-03-10.398  < 2e-16 ***
Sales8.009e-03  3.487e-04 22.971  < 2e-16 ***
ROE  2.921e-03  5.896e-06495.331  < 2e-16 ***
GTA -3.509e-03  1.174e-03 -2.989   0.0028 **
Size-5.688e-04  1.220e-04 -4.662 3.13e-06 ***
logSigma-5.401e+00  2.746e-04 -19668.028  < 2e-16 ***
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1

BHHH maximisation, 150 iterations
Return code 4: Iteration limit exceeded.
Log-likelihood: -66915.77 on 10 Df

How can I calculate McFadden's adjusted  R2 in R?
How could I reduce iteration?

Thank you,
Vanessa



2017-01-04 13:25 GMT+01:00 PIKAL Petr :
>
> Hi
>
> Although I cannot help you with your actual problem, you shall start with 
> checking your data before doing any analysis. We do not have your data so it 
> is hard to say what can be wrong. At least you shall provide result of
>
> str(T1) and/or
> str(mydata)
>
> The first message is not an error but a warning that tells you about coercing 
> some log values to NaN which can result e.g. from negative values.
>
> log(-1)
> [1] NaN
> Warning message:
> In log(-1) : NaNs produced
>
> and probably some further calculation in summary function does not like it 
> and throws error.
>
> But without data it is only a guess.
>
> And BTW, you shall post plain text not HTML.
>
> Cheers
> Petr
>
>
> > -Original Message-
> > From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of Vanessa
> > Romero
> > Sent: Wednesday, January 4, 2017 10:28 AM
> > To: r-help@r-project.org
> > Subject: [R] Tobit Regression with unbalanced Panel Data
> >
> > Hello,
> >
> > I am doing Tobit Regression in R, because my dependent variable is censored
> > at 0. I have unbalanced panel data, for 6 years, 107 companies. I use 
> > package
> > CensReg.
> >
> > I have imported my database(T1).
> >
> > I use pdata.frame to specify the structure of my panel data. Like:
> >
> >
> > *mydata<- pdata.frame (T1, index = c("firm", "year")) *
> > Afterwards:
> >
> > *Tob <- censReg(formula=Imp ~ Bath + CEOTurnover + ChangeOCF + E +
> > Sales + ROE + GTA + Size , data = mydata, method="BHHH") * (as explained
> > here:
> > https://cran.r-project.org/web/packages/censReg/vignettes/censReg.pdf)
> >
> > I got here error message:
> >
> >
> > *Warnmeldung: In log(rEff$ercomp$sigma$id) : NaNs wurden erzeugt*
> >
> > Another error message when *summary(Tob)*
> >
> >
> >
> >
> >
> > *Call: censReg(formula = Imp ~ Bath + CEOTurnover + ChangeOCF + E + Sales
> > + ROE + GTA + Size, data = mydata, method = "BHHH") Observations: Total
> > Left-censored Uncensored Right-censored 606 469 137 0 Coefficients: Fehler
> > in printCoefmat(coef(x, logSigma = logSigma), digits = digits) : 'x' must be
> > coefficient matrix/data frame*
> >
> > I am new to statistics and to R, what could be the problem or would you
> > suggest using other package.
> >
> > Thank you,
> > Vanessa
> >
> >   [[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.
>
> 
> 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 

Re: [R-es] que tal comunidad, una pregunta del paquete data.table

2017-01-06 Thread Carlos Ortega
Hola,

Una forma de hacerlo es esta:

#--

library(data.table)
set.seed(22)

DT <- data.table( x = rnorm(100), y = rnorm(100), z = sample(1:5, 100,
replace = TRUE))

DT[, Max := max(y), by=z][y == Max]

#--

Que produce este resultado:

> DT[, Max := max(y), by=z][y == Max]
xy z  Max
1: -0.9221536 1.179189 2 1.179189
2:  2.0029422 1.607435 5 1.607435
3:  0.4413632 1.648292 4 1.648292
4:  0.2195311 1.003396 3 1.003396
5: -0.7727382 1.832411 1 1.832411

Saludos,
Carlos Ortega
www.qualityexcellence.es


El 6 de enero de 2017, 4:38, eric  escribió:

> si se tiene un data.table (DT), supongamos de 100 filas por 3 columnas de
> datos numericos, como puedo hacer para obtener el correspondiente valor de
> la columna 1 si busco, por ejemplo, el maximo de la columna 2 agrupado por
> la columna 3 ?
>
> para buscar el maximo de la columna 2 escribo.
>
> DT[ , max(c2), by=c3 ]
>
> muchas gracias,
>
> saludos, eric.
>
>
>
>
> --
> Forest Engineer
> Master in Environmental and Natural Resource Economics
> Ph.D. student in Sciences of Natural Resources at La Frontera University
> Member in AguaDeTemu2030, citizen movement for Temuco with green city
> standards for living
>
> Nota: Las tildes se han omitido para asegurar compatibilidad con algunos
> lectores de correo.
>
> ___
> R-help-es mailing list
> R-help-es@r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-help-es
>



-- 
Saludos,
Carlos Ortega
www.qualityexcellence.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


[R] Problem with IRkernel Installation Solved - Instructions on how to Solve it

2017-01-06 Thread Paul Bernal
Dear friends,

Great news! I was able to install the IRkernel successfully and I am now
able to create R notebooks in Jupyter. Just in case anybody out there is
struggling with this too, here is what I did (I have Windows 8, but it will
probably work for Mac OS X as well):

1-Go to the page https://irkernel.github.io/installation
2-Open the R console (I have R version 3.3.2)
3-Go to the step where it says "Installing via supplied binary packages
(default on Windows + Mac OS X)
4-Instead of installing all the packages using one single command as
suggested in the installation instructions, go to the R console and install
all of the packages one by one, as follows
 >install.packages('repr')
 >install.packages('IRdisplay')
 >install.packages('evaluate')
 >install.packages('crayon')
 >install.packages('pbdZMQ')
 >install.packages('devtools')
 >install.packages('uuid')
 >install.packages('digest')
5-Connect to a CRAN mirror and select install packages, look for the
package githubinstall and clic on it to install it
6-Start loading each one of the packages installed like this:
 >library("repr")
 >library("IRdisplay")
 >library("evaluate")
 >library("crayon")
 >library("pbdZMQ")
 >library("devtools")
 >library("uuid")
 >library("digest")
 >library("githubinstall")
7-After this you have to update jsonlite which is a dependencie of package
githubinstall, you update jsonlite using the following command:
 >update.packages('jsonlite')
8-After this, you have to type the following commands:
 >library(httr)
 >set_config(use_proxy(url="the required IP", port=8080, username="your
network user", password="the password you use to unlock your computer"))
 >#you can get the required IP going to the command prompt and using the
command ping
 >#port has to be 8080
9-type use the command:
 >devtools::install_github('IRkernel/IRkernel')
10-Last but not least, type the following command:
 >IRkernel::installspec()

If you follow this instructions you should be able to install the IRkernel
successfully and start writing R notebooks in Jupyter.

Hope this helps,

[[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.


Re: [R] IRkernel Installation Issues

2017-01-06 Thread Paul Bernal
Dear friends,

Great news! I was able to install the IRkernel successfully and I am now
able to create R notebooks in Jupyter. Just in case anybody out there is
struggling with this too, here is what I did (I have Windows 8, but it will
probably work for Mac OS X as well):

1-Go to the page https://irkernel.github.io/installation
2-Open the R console (I have R version 3.3.2)
3-Go to the step where it says "Installing via supplied binary packages
(default on Windows + Mac OS X)
4-Instead of installing all the packages using one single command as
suggested in the installation instructions, go to the R console and install
all of the packages one by one, as follows
 >install.packages('repr')
 >install.packages('IRdisplay')
 >install.packages('evaluate')
 >install.packages('crayon')
 >install.packages('pbdZMQ')
 >install.packages('devtools')
 >install.packages('uuid')
 >install.packages('digest')
5-Connect to a CRAN mirror and select install packages, look for the
package githubinstall and clic on it to install it
6-Start loading each one of the packages installed like this:
 >library("repr")
 >library("IRdisplay")
 >library("evaluate")
 >library("crayon")
 >library("pbdZMQ")
 >library("devtools")
 >library("uuid")
 >library("digest")
 >library("githubinstall")
7-After this you have to update jsonlite which is a dependencie of package
githubinstall, you update jsonlite using the following command:
 >update.packages('jsonlite')
8-After this, you have to type the following commands:
 >library(httr)
 >set_config(use_proxy(url="the required IP", port=8080, username="your
network user", password="the password you use to unlock your computer"))
 >#you can get the required IP going to the command prompt and using the
command ping
 >#port has to be 8080
9-type use the command:
 >devtools::install_github('IRkernel/IRkernel')
10-Last but not least, type the following command:
 >IRkernel::installspec()

If you follow this instructions you should be able to install the IRkernel
successfully and start writing R notebooks in Jupyter.

Hope this helps,

Paul





2017-01-05 16:12 GMT-05:00 David Winsemius :

>
> > On Jan 5, 2017, at 11:16 AM, Paul Bernal  wrote:
> >
> > Hello everyone,
> >
> > I tried to get the IRkernel going doing the following:
> >
> > install.packages(c('repr', 'IRdisplay', 'evaluate', 'crayon', 'pbdZMQ',
> > 'devtools', 'uuid', 'digest'))
> >
> > then taking care of proxy settings by doing:
> >
> > library(devtools)
> >
> > library(httr)
> >
> > set_config(use_proxy(url="",port=8080,username="user",password="pswrd"))
> >
> > then installed package install_github
> >
> > then called library(githubinstall)
> >
> > finally install_github(('IRkernel')
>
> The mismatch of parentheses makes me doubt this was an exact copy. I
> believe the username referred to in the error refers to the username of the
> author, not your username. Notice the form of all the examples on
> `?install_github` are of the form:  install_github("klutometis/roxygen")
>
>  Why are you not trying the code suggested on the github page:
> https://github.com/IRkernel/IRkernel
>
>  install_github('IRkernel/IRkernel')
>
> (Worked for me on a Mac. No other username or pwd needed)
>
>
> >
> > However the following error popped up: "Error in username %||%
> > getOption("github.user") %||% stop("Unknown username.") :
> >  Unknown username.
> >
> > Any idea what could be wrong? I tried with buth my network username and
> > password and my github username and password without any success.
> >
> > Regards,
> >
> > Paul
> >
> >   [[alternative HTML version deleted]]
>
> R-help is a plain text mailing list.
>
> >
> > __
> > 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
>
>

[[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] testing whether clusters in a PCA plot are significantly different from one another

2017-01-06 Thread Marchesi, Julian


Rplot_PCA.pdf
Description: Rplot_PCA.pdf
__
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] que tal comunidad, una pregunta del paquete data.table

2017-01-06 Thread javier.ruben.marcuzzi
Estimado Eric

Creo que es más simple si lo piensa de otra forma, equivalente, yo plantearía 
en tener las filas (para luego buscar la primer columna).

Preguntaría:

Agrupar por columna 3,
A estos
Cuándo el valor máximo de la columna 2.

De esta forma cuándo tenga 40 columnas en lugar de 3 no tendría problemas con 
el algoritmo, solo tendría que seleccionar el valor de la columna que desea 
(porque tendría todas).

Ahora, si leo lo que usted escribe DT[, max(c2), by=c3], iría al mismo 
razonamiento que yo tengo, pero ¿porqué no le funciona?

¿Puede enviar un ejemplo reproducible? Pienso que puede ser que tenga el 
resultado en sus manos, pero no se dio cuenta.

Javier Rubén Marcuzzi

De: eric
Enviado: viernes, 6 de enero de 2017 0:38
Para: Lista R
Asunto: [R-es] que tal comunidad, una pregunta del paquete data.table

si se tiene un data.table (DT), supongamos de 100 filas por 3 columnas 
de datos numericos, como puedo hacer para obtener el correspondiente 
valor de la columna 1 si busco, por ejemplo, el maximo de la columna 2 
agrupado por la columna 3 ?

para buscar el maximo de la columna 2 escribo.

DT[ , max(c2), by=c3 ]

muchas gracias,

saludos, eric.




-- 
Forest Engineer
Master in Environmental and Natural Resource Economics
Ph.D. student in Sciences of Natural Resources at La Frontera University
Member in AguaDeTemu2030, citizen movement for Temuco with green city 
standards for living

Nota: Las tildes se han omitido para asegurar compatibilidad con algunos 
lectores de correo.

___
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] Dates and Times in R

2017-01-06 Thread Ulrik Stervbo
The lubridate package might be helpful.

HTH
Ulrik

On Fri, 6 Jan 2017 at 08:28 PIKAL Petr  wrote:

> Hi
> It strongly reminds me following fortune
>
> library(fortunes)
> fortune("surgery")
>
> Along with Posting guide you should also look at chapter 7 of R intro
> manual.
>
> Cheers
> Petr
>
> > -Original Message-
> > From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of David
> > Winsemius
> > Sent: Friday, January 6, 2017 6:13 AM
> > To: elif beyza çatalbaş 
> > Cc: r-help@r-project.org
> > Subject: Re: [R] Dates and Times in R
> >
> > You should read the Posting Guide.
> >
> > > On Jan 5, 2017, at 10:56 AM, elif beyza çatalbaş
> >  wrote:
> > >
> > > Dear Mrs/Mr
> > >
> > > I am a meteorological engineer and currently I am a master of science
> > > student in atmospheric science at Istanbul Technical University. I
> > > have data analysis and visualization lesson and I am analyzing data in
> > > R programming. I have to project in this lesson and I am working on
> > > wind energy sector because of this I chose bReeze packages to examine
> > wind data.
> > > But I am having trouble reading time,Deadlines of my project is  9
> > > January 2017. You can find my data in a attachment. I look forward to
> > > hearing from you.
> > >
> > > Sincerely,
> > >
> > > Elif Beyza ÇATALBAŞ
> > > Meteorological Engineer
> > > __
> > > 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.
>
> 
> 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 modifications of the e-mail or by delay with transfer of the
> email.
>
> In case that this e-mail forms part of business dealings:
> - the sender reserves the right to end negotiations about entering into a
> contract in any time, for any reason, and without stating any reasoning.
> - if the e-mail contains an offer, the recipient is entitled to
> immediately accept such offer; The sender of this e-mail (offer) excludes
> any acceptance of the offer on the part of the recipient containing any
> amendment or variation.
> - the sender insists on that the respective contract is concluded only
> upon an express mutual agreement on all its aspects.
> - the sender of this e-mail informs that he/she is not authorized to enter
> into any contracts on behalf of the company except for cases in which
> he/she is expressly authorized to do so in writing, and such authorization
> or power of attorney is