Re: [R] Printing matrix/table in a procedure

2019-05-15 Thread Steven Yen
Great! Thanks.

On 5/15/2019 7:00 PM, Rui Barradas wrote:
> Hello,
>
> What's wrong with
>
> test <- function(x){
>   table <- matrix(x, nrow = 4)
>   cat("\nTable:\n")
>   print(table)
>   invisible(list(table = table))
> }
>
>
> Hope this helps,
>
> Rui Barradas
>
> Às 10:33 de 15/05/19, Steven Yen escreveu:
>> Dear All,
>>
>> I would like to get a matrix (table) printed in a procedure, as
>> attempted below. Please help. Thanks.
>>
>> test<-function(x){
>>     table<-matrix(x,nrow=4)
>>     cat("\nTable:\n",table)
>> invisible(list(table=table))
>> }
>>
>> x<-1:20
>> test(x)
>>
>

-- 
st...@ntu.edu.tw (S.T. Yen)


[[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] Identificar por coordenadas geográficas una calle de una ciudad

2019-05-15 Thread Diego Martín
Muchísimas gracias a todos. Voy a echar un vistazo y, sí, os contaré qué
tal.
Un abrazo.

El jue., 16 may. 2019 a las 0:31, Javier Marcuzzi (<
javier.ruben.marcu...@gmail.com>) escribió:

> Estimados
>
> Sobre como obtener la geolocalización, aparte de lo aportado por Rubén
> Casal, también existe el api de Microsoft, lo que yo descartaría es tomar
> una base de datos con geolocalización, teóricamente andarían pero si uno
> por casualidad conoce la geografía real, se da cuenta de errores, salvo que
> en España los datos estén correctos.
>
> Javier Rubén Marcuzzi
>
> El mié., 15 may. 2019 a las 8:50, rubenfcasal ()
> escribió:
>
>> Hola a todos,
>>
>> Yo tengo empleado herramientas de este tipo hace tiempo. Básicamente
>> hacían consultas a google maps sobre direcciones y devolvían la
>> posición. El número de consultas tenía restricciones y había que darse
>> de alta en la api de google:
>> https://developers.google.com/maps/documentation/geocoding/start?csw=1
>>
>> Buscando ahora esas herramientas me encontré con la función geocode de
>> ggmap:
>>
>> https://www.rdocumentation.org/packages/ggmap/versions/2.6.1/topics/geocode
>> https://www.jessesadler.com/post/geocoding-with-r
>> podrías comenzar por esta...
>>
>> Como a mi gustan bastante las herramientas de OpenStreetMap (para cargar
>> rutas en R, ...),
>> y para no depender de google, miré también ahora si había novedades
>> sobre esto y encontré varias:
>>
>> https://datascienceplus.com/osm-nominatim-with-r-getting-locations-geo-coordinates-by-its-address
>> https://rud.is/b/2015/07/29/introducing-the-nominatim-geocoding-package
>>
>> Diego, ya nos dirás como hiciste finalmente...
>>
>> Un saludo, Rubén.
>>
>> El 15/05/2019 a las 13:16, Diego Martín escribió:
>> > Saludos estimados compañeros:
>> > ¿Alguno de ustedes sabe de alguna librería con la que
>> geolocalizar
>> >   una calle de una ciudad española?, aunque no cuenten nada más que
>> aquellas
>> > a partir de un umbral de población.
>> >  Muchas gracias.
>> >
>> >   [[alternative HTML version deleted]]
>> >
>> > ___
>> > R-help-es mailing list
>> > R-help-es@r-project.org
>> > https://stat.ethz.ch/mailman/listinfo/r-help-es
>> >
>>
>>
>> --
>> Ruben Fernandez Casal
>> https://rubenfcasal.github.io
>> Department of Mathematics
>> Faculty of Computer Science
>> Universidade da Coruña
>> Corporate email: ruben.fcasal  udc  es
>> --
>>
>> ___
>> 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] converting zipcodes to latitude/longitude

2019-05-15 Thread Jim Lemon
Hi Nicola,
Good to learn that you solved the problem. Shape files are usually a
set of polygons for the named areas.  I did some work with the "rgdal"
package a while ago and it wasn't very difficult. There might be
better methods now, so posting to R-SIG-geo is a good idea.

Jim

On Thu, May 16, 2019 at 6:30 AM Nicola Ruggiero
 wrote:
>
> Hi Jim,
>
> I ended up collaborating with someone, and, on the basis of looking at
> your code (we did take it into consideration and talk about it), we
> came up with this:
>
> library(stringr)
> numextract <- function(string){
>  str_extract(string, "\\-*\\d+\\,*\\d*")
> }
> myDataSet$zip<-numextract(myDataSet$state)
> combineddata<-merge(zipcode, myDataSet, by.x="zip", by.y="zip")
>
> So, as I understand it, we build a function the purpose of which was
> to extract the numerical value from a string value, imputed that into
> a column, then merged the two data frames together. It worked!
>
> Now I just need to figure out this thing called shape data...basically
> I need to figure out how to interpose a shape of the United States
> underneath my data points so that I can see them over the location to
> which they correspond.
>
> Nicola
>
> On Mon, May 13, 2019 at 9:09 PM Jim Lemon  wrote:
> >
> > Hi Nicola,
> > Getting the blank rows will be a bit more difficult and I don't see
> > why they should be in the final data frame, so:
> >
> > townzip<-read.table(text="waltham, Massachusetts 02451
> > Columbia, SC 29209
> >
> > Wheat Ridge , Colorado 80033
> > Charlottesville, Virginia 22902
> > Fairbanks, AK 99709
> > Montpelier, VT 05602
> > Dobbs Ferry, New York 10522
> >
> > Henderson , Kentucky 42420",
> > sep="\t",stringsAsFactors=FALSE)
> > zip_split<-function(x) {
> >  commasplit<-unlist(strsplit(x,","))
> >  state<-trimws(gsub("[[:digit:]]","",commasplit[2]))
> >  zip<-trimws(gsub("[[:alpha:]]","",commasplit[2]))
> >  return(c(commasplit[1],state,zip))
> > }
> > townzipsplit<-as.data.frame(t(sapply(townzip$V1,zip_split)))
> > rownames(townzipsplit)<-NULL
> > names(townzipsplit)<-c("town","state","zip")
> > townzipsplit$latlon<-NA
> > # I don't know the name of the zipcode column in the "zipcode" data frame
> > newzipdf<-merge(townzipsplit,zipcodedf,by.x="zip",by.y="zip")
> >
> > Jim
> >
> > On Tue, May 14, 2019 at 5:57 AM Nicola Ruggiero
> >  wrote:
> > >
> > > Hello everyone,
> > >
> > > I've downloaded Jeffrey Breen's R package "zipcode," which has the
> > > latitude and longitude for all of the US zip codes. So, this is a
> > > data.frame with 43,191 observations. That's one data frame in my
> > > environment.
> > >
> > > Then, I have another data.frame with over 100,000 observations that
> > > look like this:
> > >
> > > waltham, Massachusetts 02451
> > > Columbia, SC 29209
> > >
> > > Wheat Ridge , Colorado 80033
> > > Charlottesville, Virginia 22902
> > > Fairbanks, AK 99709
> > > Montpelier, VT 05602
> > > Dobbs Ferry, New York 10522
> > >
> > > Henderson , Kentucky 42420
> > >
> > > The spaces represent absences in the column. Regardless,
> > > I need to figure out how to write a code that would, presumably, match
> > > the zipcodes and produce another column to the data frame with the
> > > latitude and longitude. So, for example, the code would recognize
> > > 02451 above, and, in the the column next to it, the code would write
> > > 42.3765° N, 71.2356° W in the column next to it, since that's the
> > > latitude and longitude for Waltham, Massachusetts.
> > >
> > > Any idea of how to begin a code that would perform such an operation?
> > >
> > > Again, I have a data.frame with the zipcodes linked to the the
> > > latitudes and longitudes, on the one hand, and another data.frame with
> > > only zipcodes (and some holes). I need to produce the corresponding
> > > latitude/longitudes in the latter data.frame.
> > >
> > > Nicola
> > >
> > > __
> > > 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-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] how to separate string from numbers in a large txt file

2019-05-15 Thread David Winsemius



On 5/15/19 4:07 PM, Michael Boulineau wrote:

I have a wild and crazy text file, the head of which looks like this:

2016-07-01 02:50:35  hey
2016-07-01 02:51:26  waiting for plane to Edinburgh
2016-07-01 02:51:45  thinking about my boo
2016-07-01 02:52:07  nothing crappy has happened, not really
2016-07-01 02:52:20  plane went by pretty fast, didn't sleep
2016-07-01 02:54:08  no idea what time it is or where I am really
2016-07-01 02:54:17  just know it's london
2016-07-01 02:56:44  you are probably asleep
2016-07-01 02:58:45  I hope fish was fishy in a good eay
2016-07-01 02:58:56  
2016-07-01 02:59:34  
2016-07-01 03:02:48  British security is a little more rigorous...


Looks entirely not-"crazy". Typical log file format.

Two possibilities: 1) Use `read.fwf` from pkg foreign; 2) Use regex 
(i.e. the sub-function) to strip everything up to the "<". Read 
`?regex`. Since that's not a metacharacters you could use a pattern 
".+<" and replace with "".


And do read the Posting Guide. Cross-posting to StackOverflow and Rhelp, 
at least within hours of each, is considered poor manners.



--

David.



It goes on for a while. It's a big file. But I feel like it's going to
be difficult to annotate with the coreNLP library or package. I'm
doing natural language processing. In other words, I'm curious as to
how I would shave off the dates, that is, to make it look like:

 hey
 waiting for plane to Edinburgh
   thinking about my boo
 nothing crappy has happened, not really
 plane went by pretty fast, didn't sleep
 no idea what time it is or where I am really
 just know it's london
 you are probably asleep
 I hope fish was fishy in a good eay
   
 
 British security is a little more rigorous...

To be clear, then, I'm trying to clean a large text file by writing a
regular expression? such that I create a new object with no numbers or
dates.

Michael

__
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] how to separate string from numbers in a large txt file

2019-05-15 Thread Michael Boulineau
I have a wild and crazy text file, the head of which looks like this:

2016-07-01 02:50:35  hey
2016-07-01 02:51:26  waiting for plane to Edinburgh
2016-07-01 02:51:45  thinking about my boo
2016-07-01 02:52:07  nothing crappy has happened, not really
2016-07-01 02:52:20  plane went by pretty fast, didn't sleep
2016-07-01 02:54:08  no idea what time it is or where I am really
2016-07-01 02:54:17  just know it's london
2016-07-01 02:56:44  you are probably asleep
2016-07-01 02:58:45  I hope fish was fishy in a good eay
2016-07-01 02:58:56  
2016-07-01 02:59:34  
2016-07-01 03:02:48  British security is a little more rigorous...

It goes on for a while. It's a big file. But I feel like it's going to
be difficult to annotate with the coreNLP library or package. I'm
doing natural language processing. In other words, I'm curious as to
how I would shave off the dates, that is, to make it look like:

 hey
 waiting for plane to Edinburgh
  thinking about my boo
 nothing crappy has happened, not really
 plane went by pretty fast, didn't sleep
 no idea what time it is or where I am really
 just know it's london
 you are probably asleep
 I hope fish was fishy in a good eay
  
 
 British security is a little more rigorous...

To be clear, then, I'm trying to clean a large text file by writing a
regular expression? such that I create a new object with no numbers or
dates.

Michael

__
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] Muchas gracias

2019-05-15 Thread Francisco Maturana
Estimados Andrés González y José Antonio, muchas gracias por las sugerencias
con eso seguiré avanzando
Saludos
Francisco


El mié., 15 de may. de 2019 a la(s) 16:58, 
escribió:

> Envíe los mensajes para la lista R-help-es a
> r-help-es@r-project.org
>
> Para subscribirse o anular su subscripción a través de la WEB
> https://stat.ethz.ch/mailman/listinfo/r-help-es
>
> O por correo electrónico, enviando un mensaje con el texto "help" en
> el asunto (subject) o en el cuerpo a:
> r-help-es-requ...@r-project.org
>
> Puede contactar con el responsable de la lista escribiendo a:
> r-help-es-ow...@r-project.org
>
> Si responde a algún contenido de este mensaje, por favor, edite la
> linea del asunto (subject) para que el texto sea mas especifico que:
> "Re: Contents of R-help-es digest...". Además, por favor, incluya en
> la respuesta sólo aquellas partes del mensaje a las que está
> respondiendo.
>
>
> Asuntos del día:
>
>1. Re: Unir coordenas en un plano mediante linea (andre...@ugr.es)
>2. Identificar por coordenadas geográficas una calle de una
>   ciudad (Diego Martín)
>3. Re: Unir coordenas en un plano mediante linea
>   (José Antonio Palazón Ferrando)
>4. Re:  Identificar por coordenadas geográficas una calle de una
>   ciudad (rubenfcasal)
>5. Re: Como reordenar datos para analisis multiples
>   correspondencias (MCA) (Juan Abasolo)
>
> --
>
> Message: 1
> Date: Wed, 15 May 2019 12:23:53 +0200
> From: "andre...@ugr.es" 
> To: r-help-es@r-project.org
> Subject: Re: [R-es] Unir coordenas en un plano mediante linea
> Message-ID: <2bacfc37-6ae7-d842-4afc-20c9b6792...@ugr.es>
> Content-Type: text/plain; charset="utf-8"
>
> x=c(1,7,3)
>
> y=c(12,3,5)
>
> plot(x,y,type="n")
>
> polygon(x,y)
>
> Si no quieres que lo cierre
>
> polygon(x,y,fillOddEven = FALSE)
>
> El 14/05/2019 a las 17:15, Francisco Maturana escribió:
> > Buenos días, tengo 3 pares de coordenadas x,y para un conjunto de
> ciudades.
> > Estas son un punto cada una, pero quiero hacer un gráfico (en un plano x
> e
> > y) que una con una línea estos 3 puntos. He intentando pero no lo logro.
> > Alguien me podría orientar por favor.
> > Saludos y desde ya gracias
> > Francisco
> >
> > El juego de datos de ejemplo
> > Dim1(x) Dim2(y)
> > Constitucion -0.73 0.45
> > Constitucion -0.59 -0.76
> > Constitucion 0.23-0.34
> > Coronel -0.50 1.27
> > Coronel -0.24 -1.67
> > Coronel 1.70   -1.61
> > Penaflor   -0.09-0.46
> > Penaflor   -0.21-1.26
> > Penaflor 2.53   -0.90
> >
> >   [[alternative HTML version deleted]]
> >
> > ___
> > R-help-es mailing list
> > R-help-es@r-project.org
> > https://stat.ethz.ch/mailman/listinfo/r-help-es
> --
> *Andrés González Carmona *
>
> Catedrático
> Departamento de Estadística e Investigación Operativa
> Universidad de Granada
>
>
> [[alternative HTML version deleted]]
>
>
>
>
> --
>
> Message: 2
> Date: Wed, 15 May 2019 13:16:26 +0200
> From: Diego Martín 
> To: "r-help-es@r-project.org" 
> Subject: [R-es] Identificar por coordenadas geográficas una calle de
> una ciudad
> Message-ID:
> <
> cakhhlbkh0bdwpqhlam0od0uuyixzkuxd+dx26vnbtjzej0g...@mail.gmail.com>
> Content-Type: text/plain; charset="utf-8"
>
> Saludos estimados compañeros:
>¿Alguno de ustedes sabe de alguna librería con la que geolocalizar
>  una calle de una ciudad española?, aunque no cuenten nada más que aquellas
> a partir de un umbral de población.
> Muchas gracias.
>
> [[alternative HTML version deleted]]
>
>
>
>
> --
>
> Message: 3
> Date: Wed, 15 May 2019 13:39:41 +0200
> From: José Antonio Palazón Ferrando 
> To: r-help-es@r-project.org
> Subject: Re: [R-es] Unir coordenas en un plano mediante linea
> Message-ID: <63cefd4a-d08c-d3d1-4486-6a359d93e...@um.es>
> Content-Type: text/plain; charset="utf-8"; Format="flowed"
>
> Hola:
>
> Entiendo que quieres un polígono por cada nivel de "dirección",
> si es así, con esto, o algo mejor, los resuelves:
>
> x <- read.table( text = "
>Constitucion -0.73  0.45
>Constitucion -0.59 -0.76
>Constitucion  0.23 -0.34
>Coronel  -0.50  1.27
>Coronel  -0.24 -1.67
>Coronel   1.70 -1.61
>Penaflor -0.09 -0.46
>Penaflor -0.21 -1.26
>Penaflor  2.53 -0.90" )
> plot( x$V2, x$V3 )
>
> for( i in levels( x$V1 ) ){
>polygon( x[ x$V1 == i, 2 ], x[ x$V1 == i, 3 ] )
> }
>
> Seguimos
>
> El 14/5/19 a las 17:15, Francisco Maturana escribió:
> > Buenos días, tengo 3 pares de coordenadas x,y para un conjunto de
> ciudades.
> > Estas son un punto cada una, pero quiero hacer un gráfico (en un plano x
> e
> > y) que una con una línea estos 3 puntos. He intentando pero no lo 

Re: [R-es] Identificar por coordenadas geográficas una calle de una ciudad

2019-05-15 Thread Javier Marcuzzi
Estimados

Sobre como obtener la geolocalización, aparte de lo aportado por Rubén
Casal, también existe el api de Microsoft, lo que yo descartaría es tomar
una base de datos con geolocalización, teóricamente andarían pero si uno
por casualidad conoce la geografía real, se da cuenta de errores, salvo que
en España los datos estén correctos.

Javier Rubén Marcuzzi

El mié., 15 may. 2019 a las 8:50, rubenfcasal ()
escribió:

> Hola a todos,
>
> Yo tengo empleado herramientas de este tipo hace tiempo. Básicamente
> hacían consultas a google maps sobre direcciones y devolvían la
> posición. El número de consultas tenía restricciones y había que darse
> de alta en la api de google:
> https://developers.google.com/maps/documentation/geocoding/start?csw=1
>
> Buscando ahora esas herramientas me encontré con la función geocode de
> ggmap:
> https://www.rdocumentation.org/packages/ggmap/versions/2.6.1/topics/geocode
> https://www.jessesadler.com/post/geocoding-with-r
> podrías comenzar por esta...
>
> Como a mi gustan bastante las herramientas de OpenStreetMap (para cargar
> rutas en R, ...),
> y para no depender de google, miré también ahora si había novedades
> sobre esto y encontré varias:
>
> https://datascienceplus.com/osm-nominatim-with-r-getting-locations-geo-coordinates-by-its-address
> https://rud.is/b/2015/07/29/introducing-the-nominatim-geocoding-package
>
> Diego, ya nos dirás como hiciste finalmente...
>
> Un saludo, Rubén.
>
> El 15/05/2019 a las 13:16, Diego Martín escribió:
> > Saludos estimados compañeros:
> > ¿Alguno de ustedes sabe de alguna librería con la que
> geolocalizar
> >   una calle de una ciudad española?, aunque no cuenten nada más que
> aquellas
> > a partir de un umbral de población.
> >  Muchas gracias.
> >
> >   [[alternative HTML version deleted]]
> >
> > ___
> > R-help-es mailing list
> > R-help-es@r-project.org
> > https://stat.ethz.ch/mailman/listinfo/r-help-es
> >
>
>
> --
> Ruben Fernandez Casal
> https://rubenfcasal.github.io
> Department of Mathematics
> Faculty of Computer Science
> Universidade da Coruña
> Corporate email: ruben.fcasal  udc  es
> --
>
> ___
> 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-es] Como reordenar datos para analisis multiples correspondencias (MCA)

2019-05-15 Thread Javier Marcuzzi
Estimado Juan Abasolo

Habría que estudiar el caso, puede no ser tan simple, por un lado el peso
que se toma en algunos modelos está disponible, pero posiblemente antes de
esto el problema puede estar en otro lado, yo soy veterinario y veo muchas
cosas donde desde la estadística o informática dicen sobre ciertas
enfermedades, y esto no es compatible, la medicina no es tan simple para
que un ingeniero la resuelva con un algoritmo, yo llevo años en eso y lo
que en ciertas áreas da en otras trae errores, la presencia o ausencia
desde el punto estadístico o de preparación en R puede tener importancia,
pero no desde el médico, es más probable que nunca tengas ninguna de todas
estas enfermedades, o una alergia, pero alergia a un epitope, más la
inmunogenética, la no presencia tiene tantas posibilidades que
estadísticamente es muy "pesada", o en otras palabras, una persona de 100
años tiene miles de días sin morir, es demostrada su alta resistencia, o,
si los días son dosis de un antibiótico y la persona una bacteria, una
dosis altísima no la mata.

Habría que ver el caso, desde el punto de vista médico el idioma y la
alergia no tiene nada que ver, pero el idioma puede dar estadísticamente
una relación con una raza, una zona geográfica, por otro lado, por ejemplo
alergia a huevo, técnicamente el sistema inmune no reconoce al huevo,
podría ser por ejemplo albúmina, pero estas proteínas están en el huevo,
leche, sangre, y dentro de estas a cuál de todas, las posibilidades son
tantas en la medicina que pasarlo un true o false por cada característica
es crear una colección de false.

Lo correcto en R, en otras áreas de la ciencia, en medicina puede no serlo,
ese peso que usted nombra puede ser correcto, pero muy incorrecto en otra
área de la ciencia. Desconozco lo que está realizando pero tenga en cuenta
que idioma y alergia le abre un abanico muy grande.

Javier Rubén Marcuzzi

El mié., 15 may. 2019 a las 17:58, Juan Abasolo ()
escribió:

>  Es evidente que no soy demasiado ingenioso, porque con todo lo que me
> ayudaron, terminé pasando horas hasta que lo conseguí (y una vez conseguido
> pienso que tendría que haber tardado menos de la cuarta parte). Gracias,
> Jorge, también.
>
> Así que, desde este estado mental que describo, vengo con una pregunta que
> más que de R es de teoría del análisis de datos.
>
> Una vez que consigo que los datos se me ordenen en variables binarias tipo
> presencia/ausencia de los valores que toman las variables originales, al
> pedirle que haga el Análisis de Multiples Concordancias, resulta que toma
> muchísima peso la ausencia de las características. Eso no distorciona el
> análisis? ¿o estoy preguntando una tontería, porque también se puede
> caracterizar mediante la ausencia? ¿O qué?
>
> Si alguien entiende mi duda y además tiene el tiempo y la paciencia de
> explicar, agradecidísimo. Pero con señalarme qué leer, me sentiría muy
> ayudado. Soy de letras, señalen con piedad.
>
>
>
> Hau idatzi du Jorge Senán Salinas (jorge.se...@imdea.org) erabiltzaileak
> (2019 mai. 14, ar. (11:19)):
>
> > Buenos dias,
> >
> > Espero que esto te pueda ayudar. Por lo que entiendo quieres llegar a una
> > seríe de columnas boleanas de ausencia/presencia de determinada alergia o
> > idioma.
> >
> > library(tidyverse)
> >
> > ind<- c("individuo1", "individuo2", "individuo3")
> > idioma<-c( "en,es", "es,en", "es,fr,en")
> > alergia<-c(0, "huevo", "pescado,huevo")
> > color<- c("amarillo", "limon", "salmon")
> >
> > dbs<-data.frame(ind, idioma, alergia, color)
> >
> > dbs%>%gather(caracteristica, valor, 2:4)%>%
> >   separate(valor, c("v1", "v2", "v3"))%>%
> >   gather(v, valor, 3:5)%>%
> >   filter(!is.na(valor))%>%
> >   mutate(categoria_bin=paste(caracteristica, ":", valor))%>%
> >   select(ind, categoria_bin)%>%
> >   mutate(value = 1)%>%
> >   spread(categoria_bin, value, fill= 0)
> >
> > Saludos
> >
> > Jorge
> >
> >
> >
> > Jorge Senán Salinas
> > Análisis de Ciclo de Vida y Sostenibilidad
> > Grupo de Tecnología de Membranas
> > IMDEA-Agua
> >
> >
> >
> > -Mensaje original-
> > De: R-help-es [mailto:r-help-es-boun...@r-project.org] En nombre de Juan
> > Abasolo
> > Enviado el: martes, 14 de mayo de 2019 10:19
> > Para: José Antonio Palazón Ferrando 
> > CC: R-help-es 
> > Asunto: Re: [R-es] Como reordenar datos para analisis multiples
> > correspondencias (MCA)
> >
> > Mil gracias, José Antonio!
> > Creo que, entre tu recomendación y el apelo al ingenio de Javier, voy a
> > terminar generando la tabla que necesito.
> >
> > Mi problema, al contrario de lo que entiendo que les pasa a los que
> > necesitan condensar, es que necesito extender... mi ya extensa
> data.frame.
> > Pero poder pensar en el problema de otros me ayuda a entender el mío.
> >
> > Hau idatzi du José Antonio Palazón Ferrando (pala...@um.es)
> erabiltzaileak
> > (2019 mai. 14, ar. (09:03)):
> >
> > > Hola:
> > >
> > > Quizá esto pueda ser de utilidad:
> > > Se trata de prepara una “tabla” que tenga tantas columnas como
> 

Re: [R-es] Como reordenar datos para analisis multiples correspondencias (MCA)

2019-05-15 Thread Juan Abasolo
 Es evidente que no soy demasiado ingenioso, porque con todo lo que me
ayudaron, terminé pasando horas hasta que lo conseguí (y una vez conseguido
pienso que tendría que haber tardado menos de la cuarta parte). Gracias,
Jorge, también.

Así que, desde este estado mental que describo, vengo con una pregunta que
más que de R es de teoría del análisis de datos.

Una vez que consigo que los datos se me ordenen en variables binarias tipo
presencia/ausencia de los valores que toman las variables originales, al
pedirle que haga el Análisis de Multiples Concordancias, resulta que toma
muchísima peso la ausencia de las características. Eso no distorciona el
análisis? ¿o estoy preguntando una tontería, porque también se puede
caracterizar mediante la ausencia? ¿O qué?

Si alguien entiende mi duda y además tiene el tiempo y la paciencia de
explicar, agradecidísimo. Pero con señalarme qué leer, me sentiría muy
ayudado. Soy de letras, señalen con piedad.



Hau idatzi du Jorge Senán Salinas (jorge.se...@imdea.org) erabiltzaileak
(2019 mai. 14, ar. (11:19)):

> Buenos dias,
>
> Espero que esto te pueda ayudar. Por lo que entiendo quieres llegar a una
> seríe de columnas boleanas de ausencia/presencia de determinada alergia o
> idioma.
>
> library(tidyverse)
>
> ind<- c("individuo1", "individuo2", "individuo3")
> idioma<-c( "en,es", "es,en", "es,fr,en")
> alergia<-c(0, "huevo", "pescado,huevo")
> color<- c("amarillo", "limon", "salmon")
>
> dbs<-data.frame(ind, idioma, alergia, color)
>
> dbs%>%gather(caracteristica, valor, 2:4)%>%
>   separate(valor, c("v1", "v2", "v3"))%>%
>   gather(v, valor, 3:5)%>%
>   filter(!is.na(valor))%>%
>   mutate(categoria_bin=paste(caracteristica, ":", valor))%>%
>   select(ind, categoria_bin)%>%
>   mutate(value = 1)%>%
>   spread(categoria_bin, value, fill= 0)
>
> Saludos
>
> Jorge
>
>
>
> Jorge Senán Salinas
> Análisis de Ciclo de Vida y Sostenibilidad
> Grupo de Tecnología de Membranas
> IMDEA-Agua
>
>
>
> -Mensaje original-
> De: R-help-es [mailto:r-help-es-boun...@r-project.org] En nombre de Juan
> Abasolo
> Enviado el: martes, 14 de mayo de 2019 10:19
> Para: José Antonio Palazón Ferrando 
> CC: R-help-es 
> Asunto: Re: [R-es] Como reordenar datos para analisis multiples
> correspondencias (MCA)
>
> Mil gracias, José Antonio!
> Creo que, entre tu recomendación y el apelo al ingenio de Javier, voy a
> terminar generando la tabla que necesito.
>
> Mi problema, al contrario de lo que entiendo que les pasa a los que
> necesitan condensar, es que necesito extender... mi ya extensa data.frame.
> Pero poder pensar en el problema de otros me ayuda a entender el mío.
>
> Hau idatzi du José Antonio Palazón Ferrando (pala...@um.es) erabiltzaileak
> (2019 mai. 14, ar. (09:03)):
>
> > Hola:
> >
> > Quizá esto pueda ser de utilidad:
> > Se trata de prepara una “tabla” que tenga tantas columnas como
> > modalidades hay en el total de los individuos.
> > Cada columna toma el nombre de la modalidad y hacemos que cada
> > individuo tome el valor 1 en las modalidades correspondientes.
> >
> > En este texto  se
> > explica y proporciona el procedimiento para hacerlo con listas de
> > especies o caracteres, es muy fácil adaptarlo a tus necesidades.
> >
> > Seguimos
> >
> >
> >
> > El 14/5/19 a las 0:04, Juan Abasolo escribió:
> > > Gracias, Javier;
> > > Anduve buscando entre tus dos propuestas para mi encarables (plyr y
> > > reshape2) y presupongo que el problema es eso del ingenio que
> > > comentás,
> > que
> > > hay que tener y no tengo.
> > >
> > > Los paquetes me vinieron igualmente re-bien, porque me di cuenta que
> > > no tengo por qué sufrir haciéndolo a mano cada vez que encaro
> > > algunas de
> > esas
> > > situaciones.
> > >
> > > Pero lo de ordenar los datos para el MCA... el ingenio estara en
> > > alguna inlampara de casa, porque a mí no se me enciende la bombilla.
> > > Parece prudente, a falta de más, idea purgar las respuestas dobles
> > > según algún criterio, que siempre es deformar la realidad un poquito
> más.
> > >
> > >
> > >
> > > Hau idatzi du Javier Marcuzzi (javier.ruben.marcu...@gmail.com)
> > > erabiltzaileak (2019 mai. 13, al. (14:47)):
> > >
> > >> Estimado Juan Abasolo
> > >>
> > >> Para esas actividades se necesita algo de ingenio, no hay una sola
> > >> solución, para esto existen librerías como plyr, reshape2, entre
> > >> otras,
> > o
> > >> simplemente a mano, en lo personal mis primeros pasos para ordenar
> > >> fue sqldf porque conocía sql más que R, sin embargo hoy las
> > >> alternativas al respecto son muy amplias.
> > >>
> > >> Yo pienso en como debo colocar los datos en el modelo, luego en
> > >> como
> > tengo
> > >> los datos originales, y finalmente busco la forma de acomodarlos.
> > >> En
> > este
> > >> paso posiblemente es donde R tiene la mayor cantidad de
> > >> alternativas e insumo de tiempo razonando puesto que tiene algo de
> "artesanal en R".
> > >>
> > >> Javier Rubén Marcuzzi
> > >>
> 

Re: [R] converting zipcodes to latitude/longitude

2019-05-15 Thread Nicola Ruggiero
Hi Jim,

I ended up collaborating with someone, and, on the basis of looking at
your code (we did take it into consideration and talk about it), we
came up with this:

library(stringr)
numextract <- function(string){
 str_extract(string, "\\-*\\d+\\,*\\d*")
}
myDataSet$zip<-numextract(myDataSet$state)
combineddata<-merge(zipcode, myDataSet, by.x="zip", by.y="zip")

So, as I understand it, we build a function the purpose of which was
to extract the numerical value from a string value, imputed that into
a column, then merged the two data frames together. It worked!

Now I just need to figure out this thing called shape data...basically
I need to figure out how to interpose a shape of the United States
underneath my data points so that I can see them over the location to
which they correspond.

Nicola

On Mon, May 13, 2019 at 9:09 PM Jim Lemon  wrote:
>
> Hi Nicola,
> Getting the blank rows will be a bit more difficult and I don't see
> why they should be in the final data frame, so:
>
> townzip<-read.table(text="waltham, Massachusetts 02451
> Columbia, SC 29209
>
> Wheat Ridge , Colorado 80033
> Charlottesville, Virginia 22902
> Fairbanks, AK 99709
> Montpelier, VT 05602
> Dobbs Ferry, New York 10522
>
> Henderson , Kentucky 42420",
> sep="\t",stringsAsFactors=FALSE)
> zip_split<-function(x) {
>  commasplit<-unlist(strsplit(x,","))
>  state<-trimws(gsub("[[:digit:]]","",commasplit[2]))
>  zip<-trimws(gsub("[[:alpha:]]","",commasplit[2]))
>  return(c(commasplit[1],state,zip))
> }
> townzipsplit<-as.data.frame(t(sapply(townzip$V1,zip_split)))
> rownames(townzipsplit)<-NULL
> names(townzipsplit)<-c("town","state","zip")
> townzipsplit$latlon<-NA
> # I don't know the name of the zipcode column in the "zipcode" data frame
> newzipdf<-merge(townzipsplit,zipcodedf,by.x="zip",by.y="zip")
>
> Jim
>
> On Tue, May 14, 2019 at 5:57 AM Nicola Ruggiero
>  wrote:
> >
> > Hello everyone,
> >
> > I've downloaded Jeffrey Breen's R package "zipcode," which has the
> > latitude and longitude for all of the US zip codes. So, this is a
> > data.frame with 43,191 observations. That's one data frame in my
> > environment.
> >
> > Then, I have another data.frame with over 100,000 observations that
> > look like this:
> >
> > waltham, Massachusetts 02451
> > Columbia, SC 29209
> >
> > Wheat Ridge , Colorado 80033
> > Charlottesville, Virginia 22902
> > Fairbanks, AK 99709
> > Montpelier, VT 05602
> > Dobbs Ferry, New York 10522
> >
> > Henderson , Kentucky 42420
> >
> > The spaces represent absences in the column. Regardless,
> > I need to figure out how to write a code that would, presumably, match
> > the zipcodes and produce another column to the data frame with the
> > latitude and longitude. So, for example, the code would recognize
> > 02451 above, and, in the the column next to it, the code would write
> > 42.3765° N, 71.2356° W in the column next to it, since that's the
> > latitude and longitude for Waltham, Massachusetts.
> >
> > Any idea of how to begin a code that would perform such an operation?
> >
> > Again, I have a data.frame with the zipcodes linked to the the
> > latitudes and longitudes, on the one hand, and another data.frame with
> > only zipcodes (and some holes). I need to produce the corresponding
> > latitude/longitudes in the latter data.frame.
> >
> > Nicola
> >
> > __
> > 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] Different predictions with forecast::auto.arima()

2019-05-15 Thread Michael Howell
Thank you very much for your advice.

On Tue, May 14, 2019 at 11:01 PM Abby Spurdle  wrote:

> > This is definitely a statistics question still so not on topic here...
> as changing the data is exactly the kind of thing that can have this
> effect.
>
> I'm sorry.
> I disagree.
> This is a question about reproducible code.
> So, I don't see why it should be considered off topic.
>
> > >The function returned a (2,1,0) model with drift. However when I used
> the
> > >same function it returns a (1,1,0) model. There were no obvious
> differences
> > >in the code. The only thing passed to it was the data. How might this
> > >happen?
>
> Either a different version of R, a difference in the forecast package, a
> difference in one of it's imports (which there are many), or different
> input.
> If you're sure the input is the same, then it must be one of the other
> reasons.
>
> I suggest reading the documentation for the relevant forecast package
> functions.
>
> The auto.arima() function alone has many arguments.
> Changing their values may produce a more desirable model.
>
>

[[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] How to publish a new package on CRAN

2019-05-15 Thread Bert Gunter
This appears to be off topic here, but, when expanded, might make a nice
post on the R-bloggers site.

Cheers,
Bert

On Wed, May 15, 2019 at 6:10 AM J C Nash  wrote:

> In reading the original post, I could not help but get a feeling that the
> writers were
> going through an exercise in learning how to put a package on CRAN. Having
> organized "Navigating
> the R Package Universe" at UseR!2017, where Spencer Graves, Julia Silge
> and I pointed out the
> difficulties for users in finding appropriate tools among the thousands of
> packages, perhaps
> an effort to organize or modify EXISTING packages would be more useful.
>
> It is NOT that new packages are unwelcome per se, but that we continue to
> need organization and
> amalgamation of these new packages into collections or categories so that
> similar functionality
> can be accessed more efficiently. And as a retired academic, I know how
> much "new" is valued over
> "review and assessment" of existing material. I've found several "new"
> publications of codes I
> published nearly half a century ago in the literature from time to time.
> Maybe the posters could
> write RPlagiarizedCheck.
>
> JN
>
>
> On 2019-05-14 10:31 p.m., Abby Spurdle wrote:
> > And there's the R Manuals:
> > https://cran.r-project.org/manuals.html
> >
> > The most relevant one (for this purpose) is "Writing R Extensions".
> >
> >   [[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.
>

[[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] How to publish a new package on CRAN

2019-05-15 Thread J C Nash
In reading the original post, I could not help but get a feeling that the 
writers were
going through an exercise in learning how to put a package on CRAN. Having 
organized "Navigating
the R Package Universe" at UseR!2017, where Spencer Graves, Julia Silge and I 
pointed out the
difficulties for users in finding appropriate tools among the thousands of 
packages, perhaps
an effort to organize or modify EXISTING packages would be more useful.

It is NOT that new packages are unwelcome per se, but that we continue to need 
organization and
amalgamation of these new packages into collections or categories so that 
similar functionality
can be accessed more efficiently. And as a retired academic, I know how much 
"new" is valued over
"review and assessment" of existing material. I've found several "new" 
publications of codes I
published nearly half a century ago in the literature from time to time. Maybe 
the posters could
write RPlagiarizedCheck.

JN


On 2019-05-14 10:31 p.m., Abby Spurdle wrote:
> And there's the R Manuals:
> https://cran.r-project.org/manuals.html
> 
> The most relevant one (for this purpose) is "Writing R Extensions".
> 
>   [[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-es] Identificar por coordenadas geográficas una calle de una ciudad

2019-05-15 Thread rubenfcasal

Hola a todos,

Yo tengo empleado herramientas de este tipo hace tiempo. Básicamente 
hacían consultas a google maps sobre direcciones y devolvían la 
posición. El número de consultas tenía restricciones y había que darse 
de alta en la api de google:

https://developers.google.com/maps/documentation/geocoding/start?csw=1

Buscando ahora esas herramientas me encontré con la función geocode de 
ggmap:

https://www.rdocumentation.org/packages/ggmap/versions/2.6.1/topics/geocode
https://www.jessesadler.com/post/geocoding-with-r
podrías comenzar por esta...

Como a mi gustan bastante las herramientas de OpenStreetMap (para cargar 
rutas en R, ...),
y para no depender de google, miré también ahora si había novedades 
sobre esto y encontré varias:

https://datascienceplus.com/osm-nominatim-with-r-getting-locations-geo-coordinates-by-its-address
https://rud.is/b/2015/07/29/introducing-the-nominatim-geocoding-package

Diego, ya nos dirás como hiciste finalmente...

Un saludo, Rubén.

El 15/05/2019 a las 13:16, Diego Martín escribió:

Saludos estimados compañeros:
¿Alguno de ustedes sabe de alguna librería con la que geolocalizar
  una calle de una ciudad española?, aunque no cuenten nada más que aquellas
a partir de un umbral de población.
 Muchas gracias.

[[alternative HTML version deleted]]

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




--
Ruben Fernandez Casal
https://rubenfcasal.github.io
Department of Mathematics
Faculty of Computer Science
Universidade da Coruña
Corporate email: ruben.fcasal  udc  es
--

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


Re: [R-es] Unir coordenas en un plano mediante linea

2019-05-15 Thread José Antonio Palazón Ferrando

Hola:

Entiendo que quieres un polígono por cada nivel de "dirección",
si es así, con esto, o algo mejor, los resuelves:

x <- read.table( text = "
  Constitucion -0.73  0.45
  Constitucion -0.59 -0.76
  Constitucion  0.23 -0.34
  Coronel  -0.50  1.27
  Coronel  -0.24 -1.67
  Coronel   1.70 -1.61
  Penaflor -0.09 -0.46
  Penaflor -0.21 -1.26
  Penaflor  2.53 -0.90" )
plot( x$V2, x$V3 )

for( i in levels( x$V1 ) ){
  polygon( x[ x$V1 == i, 2 ], x[ x$V1 == i, 3 ] )
}

Seguimos

El 14/5/19 a las 17:15, Francisco Maturana escribió:

Buenos días, tengo 3 pares de coordenadas x,y para un conjunto de ciudades.
Estas son un punto cada una, pero quiero hacer un gráfico (en un plano x e
y) que una con una línea estos 3 puntos. He intentando pero no lo logro.
Alguien me podría orientar por favor.
Saludos y desde ya gracias
Francisco

El juego de datos de ejemplo
Dim1(x) Dim2(y)
Constitucion -0.73 0.45
Constitucion -0.59 -0.76
Constitucion 0.23-0.34
Coronel -0.50 1.27
Coronel -0.24 -1.67
Coronel 1.70   -1.61
Penaflor   -0.09-0.46
Penaflor   -0.21-1.26
Penaflor 2.53   -0.90

[[alternative HTML version deleted]]

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


--


José Antonio Palazón Ferrando
Profesor Titular. Departamento de Ecología e Hidrología.
Facultad de Biología. Universidad de Murcia.
Campus Universitario de Espinardo
30100 MURCIA-SPAIN
Telf: +34 868 88 49 80
Fax : +34 868 88 39 63
Email: pala...@um.es

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


[R-es] Identificar por coordenadas geográficas una calle de una ciudad

2019-05-15 Thread Diego Martín
Saludos estimados compañeros:
   ¿Alguno de ustedes sabe de alguna librería con la que geolocalizar
 una calle de una ciudad española?, aunque no cuenten nada más que aquellas
a partir de un umbral de población.
Muchas gracias.

[[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] Printing matrix/table in a procedure

2019-05-15 Thread Rui Barradas

Hello,

What's wrong with

test <- function(x){
  table <- matrix(x, nrow = 4)
  cat("\nTable:\n")
  print(table)
  invisible(list(table = table))
}


Hope this helps,

Rui Barradas

Às 10:33 de 15/05/19, Steven Yen escreveu:

Dear All,

I would like to get a matrix (table) printed in a procedure, as
attempted below. Please help. Thanks.

test<-function(x){
    table<-matrix(x,nrow=4)
    cat("\nTable:\n",table)
invisible(list(table=table))
}

x<-1:20
test(x)



__
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] Unir coordenas en un plano mediante linea

2019-05-15 Thread andre...@ugr.es
x=c(1,7,3)

y=c(12,3,5)

plot(x,y,type="n")

polygon(x,y)

Si no quieres que lo cierre

polygon(x,y,fillOddEven = FALSE)

El 14/05/2019 a las 17:15, Francisco Maturana escribió:
> Buenos días, tengo 3 pares de coordenadas x,y para un conjunto de ciudades.
> Estas son un punto cada una, pero quiero hacer un gráfico (en un plano x e
> y) que una con una línea estos 3 puntos. He intentando pero no lo logro.
> Alguien me podría orientar por favor.
> Saludos y desde ya gracias
> Francisco
>
> El juego de datos de ejemplo
> Dim1(x) Dim2(y)
> Constitucion -0.73 0.45
> Constitucion -0.59 -0.76
> Constitucion 0.23-0.34
> Coronel -0.50 1.27
> Coronel -0.24 -1.67
> Coronel 1.70   -1.61
> Penaflor   -0.09-0.46
> Penaflor   -0.21-1.26
> Penaflor 2.53   -0.90
>
>   [[alternative HTML version deleted]]
>
> ___
> R-help-es mailing list
> R-help-es@r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-help-es
-- 
*Andrés González Carmona *

Catedrático
Departamento de Estadística e Investigación Operativa
Universidad de Granada


[[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] Printing matrix/table in a procedure

2019-05-15 Thread Steven Yen
Dear All,

I would like to get a matrix (table) printed in a procedure, as 
attempted below. Please help. Thanks.

test<-function(x){
   table<-matrix(x,nrow=4)
   cat("\nTable:\n",table)
invisible(list(table=table))
}

x<-1:20
test(x)

-- 
st...@ntu.edu.tw (S.T. Yen)


[[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] Iterating dates over multiple ids

2019-05-15 Thread Graeme Davidson
Hi all, 

I want to create a df that repeats the dates over ids. Previously I tried 
expand.grid but this created every possible iteration of dates and ids, when 
all I want is the start and end dates repeated for each month. In other words 
01/03/19 with an end date of 28/02/19 would be unsuitable. I have also been 
told that rbind may be unsuitable when the data is scaled up to tens of 
thousands of rows. I would appreciate any suggestions. 

library(lubridate)
#get list of month dates for last 6 months
end_months <- ymd("2018-11-01")+ months(0:6)-days(1)
start_months <- ymd("2018-10-01")+ months(0:6)

#list of view ids required to make api call (pseudonymised) viewId <- 
c(26494958, 477448251, 47843527, 96382507, 537821552, 67482819)
All the best

Graeme R Davidson PhD

Data and Insight Analyst 
[[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] dealing with random.walk in intervention analysis using TSA::arimax

2019-05-15 Thread r messages
Hi Listers,

I am trying to do intervention analysis using arimax function,
typically on financial time series (random walk).

I found that the function can't handle raw random walk series unless we
supply an already differenced version of it.

example data:

random.walk <- 
ts(c(64.6100,64.8200,64.7600,64.6700,64.5300,64.6300,64.6400,64.8100,64.8500,64.8600,65.0400,65.,64.7200,65.0600,64.3100,64.4700,64.5400,64.4100,64.4100
,64.5200,64.5350,64.4900,64.2100,64.3600,64.5450,64.6100,64.7800,64.7050,64.6600,64.4600,64.5000,64.4700,64.4700,64.6400,64.6400,64.2900,64.4800,64.3100
,64.2500,64.2500,64.0300,64.1450,64.4500,64.0700,64.2500,64.2000,64.1150,64.3000,64.3600,64.4600,64.2300,64.1700,64.1800,63.9900,63.9000,64.0399,64.2600
,64.5050,64.6300,64.4100,64.4950,64.5100,64.5601,63.7300,64.1100,64.0500,64.1800,64.2700,64.3600,64.4500,64.9800,64.8400,65.,65.1500,65.3750,65.3650
,65.3500,65.9700,65.9600,65.6200,65.5600,65.6300,65.5900,65.6750,65.6650,65.4600,65.6000,65.5500,65.5250,65.4500,65.3200,65.2000,65.2500,65.5400,65.5400
,65.6850,65.9000,65.8950,65.5100,65.0900,65.3500,65.2300,65.2500,65.4400,65.6950,65.5899,65.6750,65.4800,65.3900,65.1400,65.3600,65.5200,65.5100,64.9050
,64.9300,64.9550,64.9000,64.9100,64.8800,65.1200,65.7100,65.6400,65.7100,65.7500,65.6350,65.6400,65.9100,66.2550,66.4750,66.3800,66.2900,66.3100,66.2100
,66.2300,66.3500,66.3800,66.1800,66.2800,66.2200,66.2800,66.7400,66.7450,66.6900,66.4900,66.5850,66.5600,66.5000,66.4200,66.6000,66.6300,66.6300,66.7400
,66.7100,66.5800,67.1900,67.9300,67.6100,67.5400,67.6900,67.4150,67.4600,67.6400,67.9600,68.2000,68.1600,67.8600,67.8800,68.0100,68.7300,68.4900,68.4100
,68.5300,68.5799,68.4300,68.1300,68.5600,68.2844,68.4393,68.5700,68.6200,68.4750,68.5900,68.2700,68.7600,68.7950,68.7093,68.6800,68.7000,68.6300,68.4800
,68.4150,68.4800,68.5300,68.3600,68.1750,68.4300,68.4200,68.1600,68.1900,68.3000,68.4300,68.2500,68.3850,68.5200,68.0800,67.8900,68.0664,67.8200,67.5100
,67.7200), frequency = 7)


step.function <- c(rep(0, 154), rep(1, 56))


e.g.

Below throws an exception saying the fixed length was wrong for
stats::arima.
Reason for this is because it calls stats::arima. it has an argument called
"fixed" which we use to fixed some parameters in the arima equation.
random walk typically has nothing to fix (if comes with no drift term)
however TSA::arimax force-feeds some "fixed" values, causing the exception
here.

arimax(random.walk, order=c(0,1,0), xtransf=step.function, transfer=c(1,0))

Following works, but we had to fit an extra arima(0,0,1) to our differenced
random walk. (note if we do auto.arima or we peruse acf and pacf, an extra
arima(0,0,1) isn't necessary or justified.

random.walk.diff <- diff(random.walk)
arimax(random.walk.diff, order=c(0,0,1), xtransf=step.function,
transfer=c(1,0))

It is either a bug or by design. I don't follow; I tried to debug the code
but it is hardly human readable for me, there are many acronyms which is
hard to make sense and easy to lose track of.

What do you guys think?

Thanks very much for your input.

Regards,

Qiuxiao

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