Re: [R-es] R-foro: Re: Bases de datos R

2015-04-08 Thread Jorge I Velez
Estimada Veronica,

El comando

R  ls()

deberia darte todos los objetos que tienes en el espacio de trabajo.  Si
quieres borrar un objeto en particular, por ejemplo el llamado datos,
solo debes escribir

R rm(datos)

donde rm() es la funcion remove.  Para mas ayuda consulta ?rm

Ahora, si quieres borrar TODOS los objetos de la sesion de R sin reiniciar
R, debes escribir

R  rm(list = ls())

Espero sea un poco mas claro.

Saludos cordiales,
Jorge.-



2015-04-08 15:58 GMT+10:00 pepeceb pepe...@yahoo.es:

 Hola Ver�nicasi le das la orden ls() te aparecer�n todos los objetos que
 has creadoLuego para eliminar el que quieras, basta con
 rm (objeto a eliminar)
 De todas formas, si vuelves a cargar una base de datos con el mismo
 nombre, elimina a la anterior y ya puedes trabajar con la nueva.


   De: Veronica Escorcia veronic...@hotmail.com
  Para: jose cebrian pepe...@yahoo.es
  Enviado: Mi�rcoles 8 de abril de 2015 4:30
  Asunto: R-foro: Re: Bases de datos R

 R-foro � Foros � Foro de debate � Bases de datos R
 |  | Re: Bases de datos Rde Veronica Escorcia - mi�rcoles, 8 de abril de
 2015, 03:56 |
 |   | Hola Manuel.Ya te expliqu� lo que m�s pude, no s� qu� m�s decirte
 :/ Me podr�as indicar por favor c�mo borrar todo para iniciar un nuevo
 proyecto?
 Es con Rcmdr, s�lo necesito saber c�mo eliminar las bases de datos que ya
 tengo cargadas y as� inicio de nuevo todo el proceso. Muchas gracias.
 Mostrar mensaje anterior | ResponderVer el mensaje en su contexto |

  Darse de baja de este foro  Dar de baja de todos los foros


 [[alternative HTML version deleted]]

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


[[alternative HTML version deleted]]

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


Re: [R] survreg FUNCTION

2015-04-08 Thread peter dalgaard

On 08 Apr 2015, at 10:14 , CHIRIBOGA Xavier xavier.chirib...@unine.ch wrote:

 Dear members,
 
 
 
 I am trying a survival analysis , I got:
 
 
 
 Error: could not find function survreg
 
 
 
 I already load
 
 the packages: survival
 
 the function: splines
 

Load or install? I suspect you actually did the latter.

 
 
 What can I do?
 

If installed and not loaded, load it with library(survival).

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


[R] survreg FUNCTION

2015-04-08 Thread CHIRIBOGA Xavier
Dear members,



I am trying a survival analysis , I got:



Error: could not find function survreg



I already load

the packages: survival

the function: splines



What can I do?



Thanks for you help,



Xavier

__
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] C compilation error (unknown type R_xlen_t) when installing Rmpi package

2015-04-08 Thread Henrik Bengtsson
Support for long vectors (and hence R_xlen_t) was introduced in R 3.0.0.

Your version is far outdated. If you wait a teeny but longer (after April
16) to update, you'll get R 3.2.0.

Henrik
On Apr 8, 2015 08:00, Sebastian L sl-resea...@outlook.com wrote:

 Hi,

 I am trying to use the parallel computing cluster of our university. To
 that end, I would like to install the Rmpi package on the cluster. The R
 version currently installed on the cluster is

 R version 2.15.2 (2012-10-26) -- Trick or Treat
 Platform: x86_64-redhat-linux-gnu (64-bit)

 I am trying to install the Rmpi package from the tar.gz source file, but
 encounter the following problem during the compilation process:

 What I run within R is
 install.packages(/home/myusername/Rpackages/Rmpi_0.6-5.tar.gz, repos =
 NULL, type = source, lib = /home/myusername/Rpackages/,
 configure.args=c(--with-Rmpi-libpath=/usr/mpi/gcc/openmpi-1.6.3/lib64/,--with‌​-Rmpi-type=OPENMPI,
 --with-Rmpi-include=/usr/mpi/gcc/openmpi-1.6.3/include/))

 and I get the following output with an error message:

 * installing *source* package ‘Rmpi’ ...
 ** Paket ‘Rmpi’ erfolgreich entpackt und MD5 Summen überprüft
 checking for openpty in -lutil... no
 checking for main in -lpthread... no
 configure: creating ./config.status
 config.status: creating src/Makevars
 ** libs
 gcc -m64 -std=gnu99 -I/usr/include/R -DNDEBUG -DPACKAGE_NAME=\\
 -DPACKAGE_TARNAME=\\ -DPACKAGE_VERSION=\\ -DPACKAGE_STRING=\\
 -DPACKAGE_BUGREPORT=\\ -DPACKAGE_URL=\\
 -I/usr/mpi/gcc/openmpi-1.6.3/include/  -DMPI2 -DOPENMPI
 -I/usr/local/include-fpic  -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2
 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64
 -mtune=generic  -c Rmpi.c -o Rmpi.o
 Rmpi.c: In Funktion »mpi_bcast«:
 Rmpi.c:605:2: Fehler: unbekannter Typname: »R_xlen_t«
 make: *** [Rmpi.o] Fehler 1
 ERROR: compilation failed for package ‘Rmpi’

 I can not quite figure out what happens here, and what unknown type name
 R_xlen_t possibly refers to.

 Thanks in advance


 __
 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] C compilation error (unknown type R_xlen_t) when installing Rmpi package

2015-04-08 Thread Prof Brian Ripley

On 08/04/2015 16:00, Sebastian L wrote:

Hi,

I am trying to use the parallel computing cluster of our university. To that 
end, I would like to install the Rmpi package on the cluster. The R version 
currently installed on the cluster is


This was a matter for the R-devel list as it involves compiled code: see 
the posting guide.



R version 2.15.2 (2012-10-26) -- Trick or Treat
Platform: x86_64-redhat-linux-gnu (64-bit)

I am trying to install the Rmpi package from the tar.gz source file, but 
encounter the following problem during the compilation process:

What I run within R is
install.packages(/home/myusername/Rpackages/Rmpi_0.6-5.tar.gz, repos = NULL, type = 
source, lib = /home/myusername/Rpackages/,
configure.args=c(--with-Rmpi-libpath=/usr/mpi/gcc/openmpi-1.6.3/lib64/,--with‌​-Rmpi-type=OPENMPI,
 --with-Rmpi-include=/usr/mpi/gcc/openmpi-1.6.3/include/))

and I get the following output with an error message:

* installing *source* package ‘Rmpi’ ...
** Paket ‘Rmpi’ erfolgreich entpackt und MD5 Summen überprüft
checking for openpty in -lutil... no
checking for main in -lpthread... no
configure: creating ./config.status
config.status: creating src/Makevars
** libs
gcc -m64 -std=gnu99 -I/usr/include/R -DNDEBUG -DPACKAGE_NAME=\\ -DPACKAGE_TARNAME=\\ 
-DPACKAGE_VERSION=\\ -DPACKAGE_STRING=\\ -DPACKAGE_BUGREPORT=\\ -DPACKAGE_URL=\\ 
-I/usr/mpi/gcc/openmpi-1.6.3/include/  -DMPI2 -DOPENMPI -I/usr/local/include-fpic  -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 
-fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic  -c Rmpi.c -o Rmpi.o
Rmpi.c: In Funktion »mpi_bcast«:
Rmpi.c:605:2: Fehler: unbekannter Typname: »R_xlen_t«
make: *** [Rmpi.o] Fehler 1
ERROR: compilation failed for package ‘Rmpi’

I can not quite figure out what happens here, and what unknown type name 
R_xlen_t possibly refers to.


It is a C type introduced in R 3.0.0.  Find in the CRAN archives a 
version of Rmpi as old as your version of R (or at least earlier than 
3.0.0) and install that.


Note to the maintainer (Cc:ed) -- you need to correct the R version 
dependence.


--
Brian D. Ripley,  rip...@stats.ox.ac.uk
Emeritus Professor of Applied Statistics, University of Oxford
1 South Parks Road, Oxford OX1 3TG, UK

__
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] Coxme penalized log-likelihood mismatch

2015-04-08 Thread Alexandre Lafontaine
Hi, 

I need to extract the penalized log-likehood term from coxme objects but I find 
the values stored whitin the object different than the penalized term given in 
the summary output of coxme function. Both the Null and the Integrated values 
are identical but the penalized is always off. 

Any thoughts on why and how i can extract the right value to compute the AIC 
myself? (I know an AIC value is given in the output but I need to compute it 
myself inside a loop) 

Many thanks, 

Alexandre Lafontaine


  
__
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] C compilation error (unknown type R_xlen_t) when installing Rmpi package

2015-04-08 Thread Sebastian L
Hi,

I am trying to use the parallel computing cluster of our university. To that 
end, I would like to install the Rmpi package on the cluster. The R version 
currently installed on the cluster is 

R version 2.15.2 (2012-10-26) -- Trick or Treat
Platform: x86_64-redhat-linux-gnu (64-bit)

I am trying to install the Rmpi package from the tar.gz source file, but 
encounter the following problem during the compilation process:

What I run within R is
install.packages(/home/myusername/Rpackages/Rmpi_0.6-5.tar.gz, repos = NULL, 
type = source, lib = /home/myusername/Rpackages/, 
configure.args=c(--with-Rmpi-libpath=/usr/mpi/gcc/openmpi-1.6.3/lib64/,--with‌​-Rmpi-type=OPENMPI,
 --with-Rmpi-include=/usr/mpi/gcc/openmpi-1.6.3/include/))

and I get the following output with an error message:

* installing *source* package ‘Rmpi’ ...
** Paket ‘Rmpi’ erfolgreich entpackt und MD5 Summen überprüft
checking for openpty in -lutil... no
checking for main in -lpthread... no
configure: creating ./config.status
config.status: creating src/Makevars
** libs
gcc -m64 -std=gnu99 -I/usr/include/R -DNDEBUG -DPACKAGE_NAME=\\ 
-DPACKAGE_TARNAME=\\ -DPACKAGE_VERSION=\\ -DPACKAGE_STRING=\\ 
-DPACKAGE_BUGREPORT=\\ -DPACKAGE_URL=\\ 
-I/usr/mpi/gcc/openmpi-1.6.3/include/  -DMPI2 -DOPENMPI -I/usr/local/include
-fpic  -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions 
-fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic  -c Rmpi.c -o 
Rmpi.o
Rmpi.c: In Funktion »mpi_bcast«:
Rmpi.c:605:2: Fehler: unbekannter Typname: »R_xlen_t«
make: *** [Rmpi.o] Fehler 1
ERROR: compilation failed for package ‘Rmpi’

I can not quite figure out what happens here, and what unknown type name 
R_xlen_t possibly refers to. 

Thanks in advance

  
__
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] script works in Rstudio but not with Rscript

2015-04-08 Thread Milt Epstein
Greetings.  I am new to R, but have quite a bit of experience
programming with other languages (e.g., Perl, Java, Python, shell
scripting).  I'm now working on a project where I need to use R.  A
colleague wrote a number of small scripts that work fine in Rstudio,
but a couple of them don't work when run using Rscript (which we're
planning on doing).  The behavior is basically the same on a few
different machines (two of them are Linux, one I think is a Mac).  To
run the scripts using Rscript, we put one of the following lines at
the top of the script:

#!/usr/bin/Rscript
#!/usr/bin/env Rscript

or called the script using Rscript:

Rscript scriptname

In all cases, the behavior is the same.

Here's one of the scripts:

#!/usr/bin/env Rscript

library(apcluster)
options(stringsAsFactors = FALSE)

args - commandArgs(TRUE)
num - args[1]

numClusters - num
mydata - read.csv(input_data.csv)
xData - mydata[, 1]
yData - mydata[, 2]

fit - apclusterK(negDistMat(r=2), mydata, K = numClusters)
#Leave the rest commented for now
#output - data.frame(xData, yData, c(as.data.frame(fit[1]), 
as.data.frame(fit[2]), as.data.frame(fit[3])))
#write.csv - write.table(output, file = output_AP.csv, sep = ,, row.names 
= FALSE, col.names = FALSE)

Here's a call to the script:

$ ./affinity_propagation.R 3

Attaching 

The following object is masked package::

heatmap

Trying p = -15.41969 
   Number of clusters: 17 
Error in tmpk - K : non-numeric argument to binary operator
Calls: apclusterK ... apclusterK - .local - apclusterK - apclusterK - .local
Execution halted

The line with the expression tmpk - K is from the code for the
apclusterK() function (from the apcluster library).  The
definition/value of tmpk is set using a call to the function length().
I mention this because the failure we're getting with the other script
also seems to involve an expression with call to length().  Here's the
error from calling that script:

$ ./spectral_clustering.R 3
Loading required package: methods
Error in length(tmpsig) * nc : non-numeric argument to binary operator
Calls: specc - specc - .local - matrix
Execution halted

The script is calling the specc() function in the kernlab library.

Any ideas what's going on here, why it's not working and what we can
do to get it to work?  Is there something that needs to be set or run
in .Renviron or .Rprofile, say?

Thanks.

Milt Epstein
Programmer in Computational Genomics
Institute for Genomic Biology (IGB)
University of Illinois at Urbana-Champaign (UIUC)
mepst...@illinois.edu

__
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] FW: r-sig-genetics is alive!

2015-04-08 Thread Jombart, Thibaut

Dear all, 

a small heads up for R-sig-genetics, a mailing list devoted to population 
genetics in R. See below, and sorry about the double-posting.

All the best

Thibaut


--
From: Jombart, Thibaut
Sent: 08 April 2015 17:21
To: r-sig-genet...@r-project.org
Subject: r-sig-genetics is alive!

Dear all, 

after a rather quiet existence for the last few years, it may be good to send 
this reminder: r-sig-genetics is alive!

Many awesome people have subscribed lately, and I am looking forward to seeing 
exciting discussions here. Posting guidelines have been freshly updated:
https://stat.ethz.ch/mailman/listinfo/r-sig-genetics

Coming soon: exciting news regarding future releases of a bunch of population 
genetics packages.

All the best

Thibaut
   

==
Dr Thibaut Jombart
MRC Centre for Outbreak Analysis and Modelling
Department of Infectious Disease Epidemiology
Imperial College - School of Public Health
Norfolk Place, London W2 1PG, UK
Tel. : 0044 (0)20 7594 3658
http://sites.google.com/site/thibautjombart/
http://sites.google.com/site/therepiproject/
http://adegenet.r-forge.r-project.org/
Twitter: @thibautjombart

__
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 calculate vif of each term of model in R?

2015-04-08 Thread Methekar, Pushpa (GE Transportation, Non-GE)



I am beginner in R doing modelling in R, I loaded excel sheet in R, i have 
chosen x elements and y elements then fitted model for linear and second order 
regression. Now I have both models. I am bit confused how to calculate vif for 
each term in model like

e.g model1-lm(y1~x1+x2+.x9) when I am using rms package then it's giving 
me like

vif(model1)

   x1 x2 x3 x4 x5 x6 x7

 6.679692   1.520271   1.667125   3.618439   4.931810   2.073879  13.870630

x8 x9

   220.969628 214.034135

now i want to compare each term with std vif as vif=10 and which will satisfy 
this condition i want to delete that term and update model1. i have done 
something like this

fun = function(model1) {

 for(i in 1:length(model1)){

  v=vif(model1)

 ss=any(v[i]=10)

if(ss==1){update(model1,.~.,-v[i])}

else{print(no update)}

 i-i+1

}



return(model1)

  }

fun(model1)

but giving error as

Error in if (ss == 1) { : missing value where TRUE/FALSE needed.

please tell me how do i solve this problem.



[[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] Temas para word markdown

2015-04-08 Thread daniel
Fernando, este enlace quizás te sirva https://vimeo.com/110804387

Hace ya muchos meses hice algo de esa manera, creando el template en Word,
espero siga siendo válido.

Daniel Merino


El 8 de abril de 2015, 8:44, Fernando Macedo ferm...@gmail.com escribió:

 Buenas, estaba siguiendo el hilo de Informes Periódicos en R de Jesus
 Herranz y me surgió una duda. Actualmente estoy tratando de usar
 markdown para todo así cualquier cosa que haga me queda presentable para
 informar o presentar en algún lugar. En general estoy usando html y o
 pdf principalmente porque cuando trato de compilar en word la verdad que
 queda bastante feíto.

 Alguién sabe, o puede indicarme un enlace que indique, como agregar y
 cambiar los temas para word?

 Saludos

 DMTV Fernando Macedo
 Ayudante del área Mejoramiento Genético
 Facultad de Veterinaria - UdelarR - Uruguay
 Tel: 26284291
 Cel.: 098596947
 ferm...@gmail.com

 Alcanzó la sabiduría quien supo morir tan seguro como nació.  Séneca

 El 08/04/15 a las 05:06, Jesus Herranz escribió:
  Finalmente era un tema de versión de RStudio como algunos compañeros
 habían indicado.
 
  Muchas gracias a todos.
 
 
 
 
 
  De: Carlos Ortega [mailto:c...@qualityexcellence.es]
  Enviado el: martes, 07 de abril de 2015 16:30
  Para: Jesus Herranz
  CC: Jorge I Velez; R-help-es
  Asunto: Re: [R-es] Informes periódicos con R
 
 
 
  Hola Jesús,
 
  Mira los ejemplos, videos y hasta un libro de referencia en la propia
 página del creador del paquete:
 
  http://yihui.name/knitr/
 
  Saludos,
 
  Carlos Ortega
 
  www.qualityexcellence.es
 
 
 
  El 7 de abril de 2015, 15:36, Jesus Herranz jesus.herr...@imdea.org
 escribió:
 
  Hola Jorge
 
  Perdona que sea tan pesado, pero no encuentro el fichero docx. Tampoco me
  manejo muy bien con RStudio.
 
  He insertado lo que me has dicho; pero solo tengo en la pantalla la
 opción
  “Knit HTML” y siempre me genera un HTML.
 
  He instalado “pander” pero no obtengo el docx
 
  Gracias
 
  Jesús
 
 
 
 
 
  De: Jorge I Velez [mailto:jorgeivanve...@gmail.com]
  Enviado el: martes, 07 de abril de 2015 13:54
  Para: Jesus Herranz
  CC: R-help-es
  Asunto: Re: [R-es] Informes periódicos con R
 
 
 
  Hola Jesus,
 
 
 
  La idea es que tengas un documento markdown en RStudio y que el
 encabezado
  sea similar a
 
 
 
  ---
 
  title: Aquí va tu título
 
  author: Aquí quien escribió el documento
 
  date: Y la fecha...
 
  output: word_document
 
  ---
 
 
 
  Despues de los segundos --- escribes el texto que necesitas siguiendo
 la
  sintaxis clasica de markdown.
 
 
 
  Una vez compilado el documento desde RStudio (tambien puede hacerse
  directamente desde R con la funcion source) se generara el documento
 .docx
  que contiene toda la informacion que necesitas.
 
 
 
  Espero sea un poco mas claro.
 
 
 
  Saludos,
 
  Jorge.-
 
 
 
 
 
 
 
  2015-04-07 21:50 GMT+10:00 Jesus Herranz jesus.herr...@imdea.org:
 
  Hola, Jorge
 
  Lo he mirado y parece que es una opción bastante buena, pero no logro
 saber
  cómo se salva en Word, solo lo logro en html
 
  Muchas gracias
 
  Jesús
 
 
 
 
 
 
 
  De: Jorge I Velez [mailto:jorgeivanve...@gmail.com]
  Enviado el: martes, 07 de abril de 2015 11:40
  Para: Jesus Herranz
  CC: R-help-es
  Asunto: Re: [R-es] Informes periódicos con R
 
 
 
 
  Hola Jesus,
 
  Una forma es RStudio + Markdown.  Hay infinidad de tutoriales en
 internet,
  pero la referencia basica es http://rmarkdown.rstudio.com/   Puedes
  organizar las salidas para que sean en Word, PDF o HTML.  La escongencia
  depende de lo que quieras hacer posteriormente con el informe generado.
 
  Espero sea de utiilidad.
 
  Saludos cordiales,
 
  Jorge.-
 
 
 
 
 
  2015-04-07 19:37 GMT+10:00 Jesus Herranz jesus.herr...@imdea.org:
 
  Hola
 
 
 
  Necesito elaborar un informe que se ejecutará mensualmente, ya que los
 datos
  en los que se basa irán cambiando. El informe estará en Word, y contiene
  texto fijo, tablas, gráficos y resultados obtenidos con R.
 
  El informe será ejecutado después por una persona que no sabe nada de R,
 al
  que le suministraré los scripts de R, pero debería ser bastante
 trasparente
  para él.
 
 
 
  ¿Qué paquetes me aconsejáis? y ¿alguna web con un tutorial?
 
 
 
  Prefiero algo sencillo, ya que no tengo mucho tiempo para dedicar a esto
 
 
 
  Gracias
 
 
 
  Jesús
 
 
 
 
 
 
   [[alternative HTML version deleted]]
 
 
  ___
  R-help-es mailing list
  R-help-es@r-project.org
  https://stat.ethz.ch/mailman/listinfo/r-help-es
 
 
 
 
 
 
   [[alternative HTML version deleted]]
 
 
  ___
  R-help-es mailing list
  R-help-es@r-project.org
  https://stat.ethz.ch/mailman/listinfo/r-help-es
 
 
 
 

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




-- 
Daniel

[[alternative HTML version deleted]]


Re: [R] your suggestions in MRMs

2015-04-08 Thread Sarah Goslee
Kristi,

The row names are utterly arbitrary. Each row is a separate site, and
sitelocation is a location variable (both intended to conceal the
absolute location, which is confidential since it's on private
property). It is NOT the Euclidean distance, nor is a row representing
a pair of sites.

If you look at the full example, dist() is used to calculate the
Euclidean distance as part of the MRM code.

Sarah

On Wed, Apr 8, 2015 at 1:49 PM, Kristi Glover kristi.glo...@hotmail.com wrote:
 Hi R Users,
 I was trying to  perfom multiple regression on resemblance matrices (MRMs). 
 This technique in avaiable  in ecodist package  and looked at the example 
 data to know how I need to organize my data set. I think the data is distance 
 matrix but I was wondering the rows name. For example, there are (these are 
 the subset of the data of graze)
  sitelocation forestpct
 1.1.200112.187743 63.88
 1.2.200112.186077 71.33
 2.1.200112.406362 72.45
 2.2.200112.416265 77.13
 3.1.1998 8.409213 18.35

 if we look at the first row, 1.1.2001: sitelocation (column) is 12.187.. 
 which is the euclidean distance between two points (XY cordinates). But I was 
 confused at the row name where 1.1.2001 which is to me is site1 and site1 of 
 2001. Isn't it supposed to be 0 if both are the same site.  I think I 
 misunderstood it. Any one can help me about what it is?

 I put the example for your reference

 install.packages(ecodist)
 library(ecodist)
 data(graze)
 graze[1:5,1:2]

 Thanks for your help

 KG



-- 
Sarah Goslee
http://www.functionaldiversity.org

__
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] data-mining with multiple filters applied to multiple columns

2015-04-08 Thread Morway, Eric
Using this representative dataset of a much larger dataset:

dat - read.table(textConnection(ISEG  IRCH  div  gw
 1   1   265  229
 1   2   260  298
 1   3   234  196
54   1   432  485
54  39   467  485
54  40   468  468
54  41   460  381
54  42   489  502
 1   1   265  317
 1   2   276  225
 1   3   217  164
54   1   430  489
54  39   456  495
54  40   507  607
54  41   483  424
54  42   457  404
 1   1   265  278
 1   2   287  370
 1   3   224  274
54   1   412  585
54  39   473  532
54  40   502  595
54  41   497  441
54  42   447  467
 1   1   230  258
 1   2   251  152
 1   3   199  179
54   1   412  415
54  39   439  538
54  40   474  486
54  41   477  484
54  42   413  346
 1   1   230  171
 1   2   262  171
 1   3   217  263
54   1   432  485
54  39   455  482
54  40   493  419
54  41   489  536
54  42   431  504
 1   1  1002  1090
 1   2  1222  1178
 1   3  1198  1177
54   1  1432  1485
54  39  1876  1975
54  40  1565  1646
54  41  1455  1451
54  42  1427  1524
 1   1  1002  968
 1   2  1246  1306
 1   3  1153  1158
54   1  1532  1585
54  39  1790  1889
54  40  1490  1461
54  41  1518  1536
54  42  1486  1585
 1   1  1002  1081
 1   2  1229  1262
 1   3  1142  1241
54   1  1632  1659
54  39  1797  1730
54  40  1517  1466
54  41  1527  1589
54  42  1514  1612),header=TRUE)

dat$seq - ifelse(dat$ISEG==1  dat$IRCH==1, 1, 0)
tmp - diff(dat[dat$seq==1,]$div)!=0
dat$idx - 0
dat[dat$seq==1,][c(TRUE,tmp),]$idx - 1
dat$ts - cumsum(dat$idx)
dat$iter - ave(dat$seq, dat$ts,FUN=cumsum)
dat$ct - seq(1:length(dat[,1]))

dat[1,]
#  ISEG IRCH div  gw seq idx ts iter ct
# 11 265 229   1   1  11  1

I'm attempting to carry out 2 data mining tasks:

1)  for each time step ('ts') and each ISEG within those time steps, I want
to difference the max and min 'div' values and store the result.  I got
close with this command, but the results were repeated:

with(subset(dat,ts==1  IRCH==1),
ave(div,ISEG,FUN=function(x){max(x)-min(x)}))
#  0 20  0 20  0 20

There are a few shortcomings with this line of script that I'm hoping could
be improved upon: (1) I hard-coded ts==1, ideally, the R script would
iterate over all 'ts', (2) I really only need the results printed once (0
 20), and (3) it would be nice to store the results in something like this
(the results shown next are from a brute-force hand-calculation on the dat
data.frame):

ISEG IRCH ts div_diff
   11  10
  541  1   20
   11  20
  541  2   20
   11  30
  541  3  200

2) The second data-mining attempt is a bit more convoluted and to
demonstrate what I'd like to get, here it is in parts.  First:

aggregate(gw ~ ISEG + iter, subset(dat,ts==1), sum)
  ISEG iter   gw
111  723
2   541 2321
312  706
4   542 2419
513  922
6   543 2620

Once again, ts==1 is hard-coded, but this would ideally loop through all
unique 'ts' in the dataset.  Next, with this result, I'd like to difference
the maximum and minimum 'gw' values associated with each ISEG.  I tried:

with(aggregate(gw ~ ISEG + iter, subset(dat,ts==1), sum), ave(gw, ISEG,
function(x){max(x)-min(x)}))
#Error in unique.default(x, nmax = nmax) :
#  unique() applies only to vectors

but didn't know what to do with the error.  for the result above, the
answer I'm seeking is:

ISEG diff
   1  216
  54  289

For ts==1, the value of 216 results from 922 - 706 [max(gw) - min(gw) for
ISEG==1] and the value of 289 results from 2620 - 2321 [max(gw) - min(gw)
for ISEG==54].  So, the culmination of what I'm after would be the result
from data-mining effort 1 + data-mining effort 2:

ISEG IRCH ts div_diff gw_diff
   11  10 216
  541  1   20 289
   11  20  16
  541  2   20 157
   11  30 152
  541  3  200  25

[[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] your suggestions in MRMs

2015-04-08 Thread Kristi Glover





Hi Sarah,

Thanks for the reply. I again looked at the example, but I did not find the way 
to
calculate the location variable. All example in the document
(ecodist) has the Euclidean distance. did not find the example to
conceal the absolute location. There are some example:

page 21 and 22 : iris.md - distance(iris[,1:4], mahal): it is
calculated distance matrix using four variables (I understood this one)

page 26: space.d - distance(space, eucl), here space is XY coordinate,
so on



I am just wondering how I can conceal my absolute location (XY) and make my
data compatible to your data set so that I can use your functions. I am sorry 
for bothering you, Sarah. 

example of my data set: column names (site,
XY coordinates, temp, years)

site1, 25.01;34.78 (XY cordicnate),
35degree celcius; year2001

site1, 25.01;34.78 (XY cordicnate), 33degree celcius;
year2002

site2, 25.05; 35.56 (XY coordinate); 37degree
celcius; year2001

site2, 25.05; 35.56 (XY coordinate);
32degree celcius; year2002





Thanks

 

===


 Date: Wed, 8 Apr 2015 14:23:27 -0400
 Subject: Re: [R] your suggestions in MRMs
 From: sarah.gos...@gmail.com
 To: kristi.glo...@hotmail.com
 CC: r-help@r-project.org
 
 Kristi,
 
 The row names are utterly arbitrary. Each row is a separate site, and
 sitelocation is a location variable (both intended to conceal the
 absolute location, which is confidential since it's on private
 property). It is NOT the Euclidean distance, nor is a row representing
 a pair of sites.
 
 If you look at the full example, dist() is used to calculate the
 Euclidean distance as part of the MRM code.
 
 Sarah
 
 On Wed, Apr 8, 2015 at 1:49 PM, Kristi Glover kristi.glo...@hotmail.com 
 wrote:
  Hi R Users,
  I was trying to  perfom multiple regression on resemblance matrices (MRMs). 
  This technique in avaiable  in ecodist package  and looked at the example 
  data to know how I need to organize my data set. I think the data is 
  distance matrix but I was wondering the rows name. For example, there are 
  (these are the subset of the data of graze)
   sitelocation forestpct
  1.1.200112.187743 63.88
  1.2.200112.186077 71.33
  2.1.200112.406362 72.45
  2.2.200112.416265 77.13
  3.1.1998 8.409213 18.35
 
  if we look at the first row, 1.1.2001: sitelocation (column) is 12.187.. 
  which is the euclidean distance between two points (XY cordinates). But I 
  was confused at the row name where 1.1.2001 which is to me is site1 and 
  site1 of 2001. Isn't it supposed to be 0 if both are the same site.  I 
  think I misunderstood it. Any one can help me about what it is?
 
  I put the example for your reference
 
  install.packages(ecodist)
  library(ecodist)
  data(graze)
  graze[1:5,1:2]
 
  Thanks for your help
 
  KG
 
 
 
 -- 
 Sarah Goslee
 http://www.functionaldiversity.org

  
[[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] your suggestions in MRMs

2015-04-08 Thread Sarah Goslee
Kristi,

You're completely missing the point, I think.

Instead of providing X,Y coordinates in the sample dataset graze
within the ecodist package, I provided one location, X if you'd like,
called sitelocation.

If you look at the example in ?MRM,

data(graze)
LOAR10.mrm - MRM(dist(LOAR10) ~ dist(sitelocation) + dist(forestpct),
data=graze, nperm=100)

This is a toy example,with only one species, geographic distance, and
another potential explanatory variable.

dist(LOAR10) - species distance; you'd use whatever set of species
you're studying

dist(sitelocation) - geographic distance, you'd use your x and y
coordinates as in dist(xy.matrix)

dist(forestpct) - you'd use whatever variable or variables are
appropriate for your study


I concealed the location of these sites BEFORE I made the data public,
which is why there's one location variable instead of x,y coordinates.

Each row of graze is a single site, with some information associated.

You don't need to conceal your location for your own analysis. You
just need to use the appropriate data within the dist() command to
calculate the distances, and with the appropriate distance metrics if
Euclidean isn't appropriate for your data.

Reading the papers cited in ?MRM might help you understand the logic a
bit better.

Sarah


On Wed, Apr 8, 2015 at 3:01 PM, Kristi Glover kristi.glo...@hotmail.com wrote:
 Hi Sarah,
 Thanks for the reply. I again looked at the example, but I did not find the
 way to calculate the location variable. All example in the document
 (ecodist) has the Euclidean distance. did not find the example to conceal
 the absolute location. There are some example:
 page 21 and 22 : iris.md - distance(iris[,1:4], mahal): it is calculated
 distance matrix using four variables (I understood this one)
 page 26: space.d - distance(space, eucl), here space is XY coordinate, so
 on

 I am just wondering how I can conceal my absolute location (XY) and make my
 data compatible to your data set so that I can use your functions. I am
 sorry for bothering you, Sarah.

 example of my data set: column names (site, XY coordinates, temp, years)

 site1, 25.01;34.78 (XY cordicnate), 35degree celcius; year2001

 site1, 25.01;34.78 (XY cordicnate), 33degree celcius; year2002

 site2, 25.05; 35.56 (XY coordinate); 37degree celcius; year2001

 site2, 25.05; 35.56 (XY coordinate); 32degree celcius; year2002



 Thanks



 ===


 Date: Wed, 8 Apr 2015 14:23:27 -0400
 Subject: Re: [R] your suggestions in MRMs
 From: sarah.gos...@gmail.com
 To: kristi.glo...@hotmail.com
 CC: r-help@r-project.org

 Kristi,

 The row names are utterly arbitrary. Each row is a separate site, and
 sitelocation is a location variable (both intended to conceal the
 absolute location, which is confidential since it's on private
 property). It is NOT the Euclidean distance, nor is a row representing
 a pair of sites.

 If you look at the full example, dist() is used to calculate the
 Euclidean distance as part of the MRM code.

 Sarah

 On Wed, Apr 8, 2015 at 1:49 PM, Kristi Glover kristi.glo...@hotmail.com
 wrote:
  Hi R Users,
  I was trying to perfom multiple regression on resemblance matrices
  (MRMs). This technique in avaiable in ecodist package and looked at the
  example data to know how I need to organize my data set. I think the data 
  is
  distance matrix but I was wondering the rows name. For example, there are
  (these are the subset of the data of graze)
  sitelocation forestpct
  1.1.2001 12.187743 63.88
  1.2.2001 12.186077 71.33
  2.1.2001 12.406362 72.45
  2.2.2001 12.416265 77.13
  3.1.1998 8.409213 18.35
 
  if we look at the first row, 1.1.2001: sitelocation (column) is 12.187..
  which is the euclidean distance between two points (XY cordinates). But I
  was confused at the row name where 1.1.2001 which is to me is site1 and
  site1 of 2001. Isn't it supposed to be 0 if both are the same site. I
  think I misunderstood it. Any one can help me about what it is?
 
  I put the example for your reference
 
  install.packages(ecodist)
  library(ecodist)
  data(graze)
  graze[1:5,1:2]
 
  Thanks for your help
 
  KG
 


 --
 Sarah Goslee
 http://www.functionaldiversity.org



-- 
Sarah Goslee
http://www.stringpage.com
http://www.sarahgoslee.com
http://www.functionaldiversity.org

__
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] script works in Rstudio but not with Rscript

2015-04-08 Thread Henrik Bengtsson
Does it work with R -f script?  If so, then it's because Rscript does not
attaching methods package by default, but R does. Try loading methods at
the top of your script.

My $.02

Henrik
On Apr 8, 2015 07:41, Milt Epstein mepst...@illinois.edu wrote:

 Greetings.  I am new to R, but have quite a bit of experience
 programming with other languages (e.g., Perl, Java, Python, shell
 scripting).  I'm now working on a project where I need to use R.  A
 colleague wrote a number of small scripts that work fine in Rstudio,
 but a couple of them don't work when run using Rscript (which we're
 planning on doing).  The behavior is basically the same on a few
 different machines (two of them are Linux, one I think is a Mac).  To
 run the scripts using Rscript, we put one of the following lines at
 the top of the script:

 #!/usr/bin/Rscript
 #!/usr/bin/env Rscript

 or called the script using Rscript:

 Rscript scriptname

 In all cases, the behavior is the same.

 Here's one of the scripts:

 #!/usr/bin/env Rscript

 library(apcluster)
 options(stringsAsFactors = FALSE)

 args - commandArgs(TRUE)
 num - args[1]

 numClusters - num
 mydata - read.csv(input_data.csv)
 xData - mydata[, 1]
 yData - mydata[, 2]

 fit - apclusterK(negDistMat(r=2), mydata, K = numClusters)
 #Leave the rest commented for now
 #output - data.frame(xData, yData, c(as.data.frame(fit[1]),
 as.data.frame(fit[2]), as.data.frame(fit[3])))
 #write.csv - write.table(output, file = output_AP.csv, sep = ,,
 row.names = FALSE, col.names = FALSE)

 Here's a call to the script:

 $ ./affinity_propagation.R 3

 Attaching

 The following object is masked package::

 heatmap

 Trying p = -15.41969
Number of clusters: 17
 Error in tmpk - K : non-numeric argument to binary operator
 Calls: apclusterK ... apclusterK - .local - apclusterK - apclusterK -
 .local
 Execution halted

 The line with the expression tmpk - K is from the code for the
 apclusterK() function (from the apcluster library).  The
 definition/value of tmpk is set using a call to the function length().
 I mention this because the failure we're getting with the other script
 also seems to involve an expression with call to length().  Here's the
 error from calling that script:

 $ ./spectral_clustering.R 3
 Loading required package: methods
 Error in length(tmpsig) * nc : non-numeric argument to binary operator
 Calls: specc - specc - .local - matrix
 Execution halted

 The script is calling the specc() function in the kernlab library.

 Any ideas what's going on here, why it's not working and what we can
 do to get it to work?  Is there something that needs to be set or run
 in .Renviron or .Rprofile, say?

 Thanks.

 Milt Epstein
 Programmer in Computational Genomics
 Institute for Genomic Biology (IGB)
 University of Illinois at Urbana-Champaign (UIUC)
 mepst...@illinois.edu

 __
 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] your suggestions in MRMs

2015-04-08 Thread Kristi Glover
Hi R Users,
I was trying to  perfom multiple regression on resemblance matrices (MRMs). 
This technique in avaiable  in ecodist package  and looked at the example 
data to know how I need to organize my data set. I think the data is distance 
matrix but I was wondering the rows name. For example, there are (these are the 
subset of the data of graze) 
 sitelocation forestpct
1.1.200112.187743 63.88
1.2.200112.186077 71.33
2.1.200112.406362 72.45
2.2.200112.416265 77.13
3.1.1998 8.409213 18.35

if we look at the first row, 1.1.2001: sitelocation (column) is 12.187.. which 
is the euclidean distance between two points (XY cordinates). But I was 
confused at the row name where 1.1.2001 which is to me is site1 and site1 of 
2001. Isn't it supposed to be 0 if both are the same site.  I think I 
misunderstood it. Any one can help me about what it is? 

I put the example for your reference

install.packages(ecodist)
library(ecodist)
data(graze)
graze[1:5,1:2]

Thanks for your help

KG



  
[[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] extracting slot coords from a Polygons class object

2015-04-08 Thread Monica Pisica

Hi,

 

I am struggling to extract the polygon vertices from a list of an object class 
Polygons, specifically the slot coords.

 

 I have a point, and i draw a buffer around with gBuffer, i am extracting 
the polygon form the SpatialPolygons class and i end up with a list of 1 one 
object Polygons class that seems to have slots, but if i try to extract them i 
get an error. 

 

So here it goes after i load the respective libraries: sp, maptools, rgdal, 
rgeos

pt1 - data.frame(x=217680.2, y = 3817555)

coordinates(pt1) - c(x, y)

crs = +proj=utm +zone=11 +datum=NAD83 +units=m +no_defs +ellps=GRS80 
+towgs84=0,0,0

 

proj4string(pt1) - CRS(crs)

pt1.cpoly - gBuffer(pt1, width = 100, byid = TRUE)

 

pt1.cpoly

class   : SpatialPolygons 

features: 1 

extent  : 217580.2, 217780.2, 3817455, 3817655  (xmin, xmax, ymin, ymax)

coord. ref. : +proj=utm +zone=11 +datum=NAD83 +units=m +no_defs +ellps=GRS80 
+towgs84=0,0,0

 

pt1.poly - pt1.cpoly@polygons

 

pt1.poly

[[1]]

An object of class Polygons

Slot Polygons:

[[1]]

An object of class Polygon

Slot labpt:

[1]  217680.2 3817554.7

 

Slot area:

[1] 30901.7

 

Slot hole:

[1] FALSE

 

Slot ringDir:

[1] 1

 

Slot coords:

 x   y

 [1,] 217780.2 3817555

 [2,] 217775.3 3817524

 [3,] 217761.1 3817496

 [4,] 217739.0 3817474

Etc. …..

 

pt1.crd - pt1.poly[[1]]@coords

Error: no slot of name coords for this object of class Polygons

 

So my question is: How do i access the coords slot i clearly see when i print 
pt1.poly on the screen? 



Thanks for any help,



Monica
__
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] script works in Rstudio but not with Rscript

2015-04-08 Thread Henrik Bengtsson
On Wed, Apr 8, 2015 at 11:20 AM, Milt Epstein mepst...@illinois.edu wrote:
 OK, this suggestion brings up some interesting results.  No solution,
 however.  But it's interesting ... and maybe some helpful leads.

 The basic/short answer to your question is no, it doesn't work with R
 -f script.

 The longer answer: Note that the script is currently set up to be
 called with a command line argument, ./affinity_propagation.R 3.  So
 first I tried R -f affinity_propagation.R 3.  That failed, but
 because it wasn't using the 3 as an argument.  So I modified the
 code to hard-code the value 3 in there and not read the command line
 argument using commandArgs(TRUE).  Then I ran the script using
 ./affinity_propagation.R -- and it worked!  R -f
 affinity_propagation.R also worked.

 Then I noticed the --args command line option for R, and I ran R -f
 affinity_propagation.R --args 3 on the original script, and it
 failed, the same error as I described below.

 Also, when you say Try loading methods, do you mean just a line like
 the following?:

 library(methods)

 I tried that as well, and it didn't help, same error.

Yes, that's what I meant.  My suggestion was just a guess given that
it is not that uncommon to see cases where a script works with 'R' but
not with 'Rscript'.  From your answers/tests, it's seems clear that
your problem now has to do with parsing arguments.

/Henrik


 So, given all that, any new ideas?  Is the call to commandArgs()
 screwing something up?  Can that be fixed somehow?  Is there another
 library/function I could/should use to read command line arguments?

 Hmmm, playing around with things some more, it looks like if I do:

 num - as.integer(args[1])

 rather than:

 num - args[1]

 things work.  So maybe this is an issue with types, scalar vs. array,
 number vs. string?

 Milt Epstein
 Programmer in Computational Genomics
 Institute for Genomic Biology (IGB)
 University of Illinois at Urbana-Champaign (UIUC)
 mepst...@illinois.edu


 On Wed, 8 Apr 2015, Henrik Bengtsson wrote:

 Does it work with R -f script?  If so, then it's because Rscript does not
 attaching methods package by default, but R does. Try loading methods at
 the top of your script.

 My $.02

 Henrik
 On Apr 8, 2015 07:41, Milt Epstein mepst...@illinois.edu wrote:

  Greetings.  I am new to R, but have quite a bit of experience
  programming with other languages (e.g., Perl, Java, Python, shell
  scripting).  I'm now working on a project where I need to use R.  A
  colleague wrote a number of small scripts that work fine in Rstudio,
  but a couple of them don't work when run using Rscript (which we're
  planning on doing).  The behavior is basically the same on a few
  different machines (two of them are Linux, one I think is a Mac).  To
  run the scripts using Rscript, we put one of the following lines at
  the top of the script:
 
  #!/usr/bin/Rscript
  #!/usr/bin/env Rscript
 
  or called the script using Rscript:
 
  Rscript scriptname
 
  In all cases, the behavior is the same.
 
  Here's one of the scripts:
 
  #!/usr/bin/env Rscript
 
  library(apcluster)
  options(stringsAsFactors = FALSE)
 
  args - commandArgs(TRUE)
  num - args[1]
 
  numClusters - num
  mydata - read.csv(input_data.csv)
  xData - mydata[, 1]
  yData - mydata[, 2]
 
  fit - apclusterK(negDistMat(r=2), mydata, K = numClusters)
  #Leave the rest commented for now
  #output - data.frame(xData, yData, c(as.data.frame(fit[1]),
  as.data.frame(fit[2]), as.data.frame(fit[3])))
  #write.csv - write.table(output, file = output_AP.csv, sep = ,,
  row.names = FALSE, col.names = FALSE)
 
  Here's a call to the script:
 
  $ ./affinity_propagation.R 3
 
  Attaching
 
  The following object is masked package::
 
  heatmap
 
  Trying p = -15.41969
 Number of clusters: 17
  Error in tmpk - K : non-numeric argument to binary operator
  Calls: apclusterK ... apclusterK - .local - apclusterK - apclusterK -
  .local
  Execution halted
 
  The line with the expression tmpk - K is from the code for the
  apclusterK() function (from the apcluster library).  The
  definition/value of tmpk is set using a call to the function length().
  I mention this because the failure we're getting with the other script
  also seems to involve an expression with call to length().  Here's the
  error from calling that script:
 
  $ ./spectral_clustering.R 3
  Loading required package: methods
  Error in length(tmpsig) * nc : non-numeric argument to binary operator
  Calls: specc - specc - .local - matrix
  Execution halted
 
  The script is calling the specc() function in the kernlab library.
 
  Any ideas what's going on here, why it's not working and what we can
  do to get it to work?  Is there something that needs to be set or run
  in .Renviron or .Rprofile, say?
 
  Thanks.
 
  Milt Epstein
  Programmer in Computational Genomics
  Institute for Genomic Biology (IGB)
  University of Illinois at Urbana-Champaign (UIUC)
  mepst...@illinois.edu
 
  

Re: [R] extracting slot coords from a Polygons class object

2015-04-08 Thread Sarah Goslee
You didn't parse the output you pasted in correctly:

pt1.cpoly@polygons[[1]]@Polygons[[1]]@coords

or

coordinates(pt1.cpoly@polygons[[1]]@Polygons[[1]])

 class(pt1.cpoly)
[1] SpatialPolygons
attr(,package)
[1] sp

So see
 ?SpatialPolygons-class
for details.

Sarah

On Wed, Apr 8, 2015 at 5:07 PM, Monica Pisica pisican...@hotmail.com wrote:

 Hi,



 I am struggling to extract the polygon vertices from a list of an object 
 class Polygons, specifically the slot coords.



  I have a point, and i draw a buffer around with gBuffer, i am extracting 
 the polygon form the SpatialPolygons class and i end up with a list of 1 one 
 object Polygons class that seems to have slots, but if i try to extract them 
 i get an error.



 So here it goes after i load the respective libraries: sp, maptools, rgdal, 
 rgeos

 pt1 - data.frame(x=217680.2, y = 3817555)

 coordinates(pt1) - c(x, y)

 crs = +proj=utm +zone=11 +datum=NAD83 +units=m +no_defs +ellps=GRS80 
 +towgs84=0,0,0



 proj4string(pt1) - CRS(crs)

 pt1.cpoly - gBuffer(pt1, width = 100, byid = TRUE)



 pt1.cpoly

 class   : SpatialPolygons

 features: 1

 extent  : 217580.2, 217780.2, 3817455, 3817655  (xmin, xmax, ymin, ymax)

 coord. ref. : +proj=utm +zone=11 +datum=NAD83 +units=m +no_defs +ellps=GRS80 
 +towgs84=0,0,0



 pt1.poly - pt1.cpoly@polygons



 pt1.poly

 [[1]]

 An object of class Polygons

 Slot Polygons:

 [[1]]

 An object of class Polygon

 Slot labpt:

 [1]  217680.2 3817554.7



 Slot area:

 [1] 30901.7



 Slot hole:

 [1] FALSE



 Slot ringDir:

 [1] 1



 Slot coords:

  x   y

  [1,] 217780.2 3817555

  [2,] 217775.3 3817524

  [3,] 217761.1 3817496

  [4,] 217739.0 3817474

 Etc. …..



 pt1.crd - pt1.poly[[1]]@coords

 Error: no slot of name coords for this object of class Polygons



 So my question is: How do i access the coords slot i clearly see when i 
 print pt1.poly on the screen?



 Thanks for any help,



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



-- 
Sarah Goslee
http://www.functionaldiversity.org

__
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] extracting slot coords from a Polygons class object

2015-04-08 Thread MacQueen, Don
It would be better to ask this question on r-sig-geo. More people there
are more familiar with the structure of Spatial{*} classes.

-Don

-- 
Don MacQueen

Lawrence Livermore National Laboratory
7000 East Ave., L-627
Livermore, CA 94550
925-423-1062





On 4/8/15, 2:07 PM, Monica Pisica pisican...@hotmail.com wrote:


Hi,

 

I am struggling to extract the polygon vertices from a list of an object
class Polygons, specifically the slot coords.

 

 I have a point, and i draw a buffer around with gBuffer, i am
extracting the polygon form the SpatialPolygons class and i end up with
a list of 1 one object Polygons class that seems to have slots, but if i
try to extract them i get an error.

 

So here it goes after i load the respective libraries: sp, maptools,
rgdal, rgeos

pt1 - data.frame(x=217680.2, y = 3817555)

coordinates(pt1) - c(x, y)

crs = +proj=utm +zone=11 +datum=NAD83 +units=m +no_defs +ellps=GRS80
+towgs84=0,0,0

 

proj4string(pt1) - CRS(crs)

pt1.cpoly - gBuffer(pt1, width = 100, byid = TRUE)

 

pt1.cpoly

class   : SpatialPolygons

features: 1 

extent  : 217580.2, 217780.2, 3817455, 3817655  (xmin, xmax, ymin,
ymax)

coord. ref. : +proj=utm +zone=11 +datum=NAD83 +units=m +no_defs
+ellps=GRS80 +towgs84=0,0,0

 

pt1.poly - pt1.cpoly@polygons

 

pt1.poly

[[1]]

An object of class Polygons

Slot Polygons:

[[1]]

An object of class Polygon

Slot labpt:

[1]  217680.2 3817554.7

 

Slot area:

[1] 30901.7

 

Slot hole:

[1] FALSE

 

Slot ringDir:

[1] 1

 

Slot coords:

 x   y

 [1,] 217780.2 3817555

 [2,] 217775.3 3817524

 [3,] 217761.1 3817496

 [4,] 217739.0 3817474

Etc. Š..

 

pt1.crd - pt1.poly[[1]]@coords

Error: no slot of name coords for this object of class Polygons

 

So my question is: How do i access the coords slot i clearly see when i
print pt1.poly on the screen?



Thanks for any help,



Monica   
__
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] script works in Rstudio but not with Rscript

2015-04-08 Thread Milt Epstein
OK, this suggestion brings up some interesting results.  No solution,
however.  But it's interesting ... and maybe some helpful leads.

The basic/short answer to your question is no, it doesn't work with R
-f script.

The longer answer: Note that the script is currently set up to be
called with a command line argument, ./affinity_propagation.R 3.  So
first I tried R -f affinity_propagation.R 3.  That failed, but
because it wasn't using the 3 as an argument.  So I modified the
code to hard-code the value 3 in there and not read the command line
argument using commandArgs(TRUE).  Then I ran the script using
./affinity_propagation.R -- and it worked!  R -f
affinity_propagation.R also worked.

Then I noticed the --args command line option for R, and I ran R -f
affinity_propagation.R --args 3 on the original script, and it
failed, the same error as I described below.

Also, when you say Try loading methods, do you mean just a line like
the following?:

library(methods)

I tried that as well, and it didn't help, same error.

So, given all that, any new ideas?  Is the call to commandArgs()
screwing something up?  Can that be fixed somehow?  Is there another
library/function I could/should use to read command line arguments?

Hmmm, playing around with things some more, it looks like if I do:

num - as.integer(args[1])

rather than:

num - args[1]

things work.  So maybe this is an issue with types, scalar vs. array,
number vs. string?

Milt Epstein
Programmer in Computational Genomics
Institute for Genomic Biology (IGB)
University of Illinois at Urbana-Champaign (UIUC)
mepst...@illinois.edu


On Wed, 8 Apr 2015, Henrik Bengtsson wrote:

 Does it work with R -f script?  If so, then it's because Rscript does not
 attaching methods package by default, but R does. Try loading methods at
 the top of your script.
 
 My $.02
 
 Henrik
 On Apr 8, 2015 07:41, Milt Epstein mepst...@illinois.edu wrote:
 
  Greetings.  I am new to R, but have quite a bit of experience
  programming with other languages (e.g., Perl, Java, Python, shell
  scripting).  I'm now working on a project where I need to use R.  A
  colleague wrote a number of small scripts that work fine in Rstudio,
  but a couple of them don't work when run using Rscript (which we're
  planning on doing).  The behavior is basically the same on a few
  different machines (two of them are Linux, one I think is a Mac).  To
  run the scripts using Rscript, we put one of the following lines at
  the top of the script:
 
  #!/usr/bin/Rscript
  #!/usr/bin/env Rscript
 
  or called the script using Rscript:
 
  Rscript scriptname
 
  In all cases, the behavior is the same.
 
  Here's one of the scripts:
 
  #!/usr/bin/env Rscript
 
  library(apcluster)
  options(stringsAsFactors = FALSE)
 
  args - commandArgs(TRUE)
  num - args[1]
 
  numClusters - num
  mydata - read.csv(input_data.csv)
  xData - mydata[, 1]
  yData - mydata[, 2]
 
  fit - apclusterK(negDistMat(r=2), mydata, K = numClusters)
  #Leave the rest commented for now
  #output - data.frame(xData, yData, c(as.data.frame(fit[1]),
  as.data.frame(fit[2]), as.data.frame(fit[3])))
  #write.csv - write.table(output, file = output_AP.csv, sep = ,,
  row.names = FALSE, col.names = FALSE)
 
  Here's a call to the script:
 
  $ ./affinity_propagation.R 3
 
  Attaching
 
  The following object is masked package::
 
  heatmap
 
  Trying p = -15.41969
 Number of clusters: 17
  Error in tmpk - K : non-numeric argument to binary operator
  Calls: apclusterK ... apclusterK - .local - apclusterK - apclusterK -
  .local
  Execution halted
 
  The line with the expression tmpk - K is from the code for the
  apclusterK() function (from the apcluster library).  The
  definition/value of tmpk is set using a call to the function length().
  I mention this because the failure we're getting with the other script
  also seems to involve an expression with call to length().  Here's the
  error from calling that script:
 
  $ ./spectral_clustering.R 3
  Loading required package: methods
  Error in length(tmpsig) * nc : non-numeric argument to binary operator
  Calls: specc - specc - .local - matrix
  Execution halted
 
  The script is calling the specc() function in the kernlab library.
 
  Any ideas what's going on here, why it's not working and what we can
  do to get it to work?  Is there something that needs to be set or run
  in .Renviron or .Rprofile, say?
 
  Thanks.
 
  Milt Epstein
  Programmer in Computational Genomics
  Institute for Genomic Biology (IGB)
  University of Illinois at Urbana-Champaign (UIUC)
  mepst...@illinois.edu
 
  __
  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 

Re: [R] script works in Rstudio but not with Rscript

2015-04-08 Thread William Dunlap
  args - commandArgs(TRUE)
  num - args[1]

and then you get a complaint about something not being numeric.
commandArgs() returns a character vector so try
   num - as.numeric(args[1])
and you may as well preface it with
   stopifnot(length(args)0)


Bill Dunlap
TIBCO Software
wdunlap tibco.com

On Wed, Apr 8, 2015 at 11:20 AM, Milt Epstein mepst...@illinois.edu wrote:

 OK, this suggestion brings up some interesting results.  No solution,
 however.  But it's interesting ... and maybe some helpful leads.

 The basic/short answer to your question is no, it doesn't work with R
 -f script.

 The longer answer: Note that the script is currently set up to be
 called with a command line argument, ./affinity_propagation.R 3.  So
 first I tried R -f affinity_propagation.R 3.  That failed, but
 because it wasn't using the 3 as an argument.  So I modified the
 code to hard-code the value 3 in there and not read the command line
 argument using commandArgs(TRUE).  Then I ran the script using
 ./affinity_propagation.R -- and it worked!  R -f
 affinity_propagation.R also worked.

 Then I noticed the --args command line option for R, and I ran R -f
 affinity_propagation.R --args 3 on the original script, and it
 failed, the same error as I described below.

 Also, when you say Try loading methods, do you mean just a line like
 the following?:

 library(methods)

 I tried that as well, and it didn't help, same error.

 So, given all that, any new ideas?  Is the call to commandArgs()
 screwing something up?  Can that be fixed somehow?  Is there another
 library/function I could/should use to read command line arguments?

 Hmmm, playing around with things some more, it looks like if I do:

 num - as.integer(args[1])

 rather than:

 num - args[1]

 things work.  So maybe this is an issue with types, scalar vs. array,
 number vs. string?

 Milt Epstein
 Programmer in Computational Genomics
 Institute for Genomic Biology (IGB)
 University of Illinois at Urbana-Champaign (UIUC)
 mepst...@illinois.edu


 On Wed, 8 Apr 2015, Henrik Bengtsson wrote:

  Does it work with R -f script?  If so, then it's because Rscript does not
  attaching methods package by default, but R does. Try loading methods at
  the top of your script.
 
  My $.02
 
  Henrik
  On Apr 8, 2015 07:41, Milt Epstein mepst...@illinois.edu wrote:
 
   Greetings.  I am new to R, but have quite a bit of experience
   programming with other languages (e.g., Perl, Java, Python, shell
   scripting).  I'm now working on a project where I need to use R.  A
   colleague wrote a number of small scripts that work fine in Rstudio,
   but a couple of them don't work when run using Rscript (which we're
   planning on doing).  The behavior is basically the same on a few
   different machines (two of them are Linux, one I think is a Mac).  To
   run the scripts using Rscript, we put one of the following lines at
   the top of the script:
  
   #!/usr/bin/Rscript
   #!/usr/bin/env Rscript
  
   or called the script using Rscript:
  
   Rscript scriptname
  
   In all cases, the behavior is the same.
  
   Here's one of the scripts:
  
   #!/usr/bin/env Rscript
  
   library(apcluster)
   options(stringsAsFactors = FALSE)
  
   args - commandArgs(TRUE)
   num - args[1]
  
   numClusters - num
   mydata - read.csv(input_data.csv)
   xData - mydata[, 1]
   yData - mydata[, 2]
  
   fit - apclusterK(negDistMat(r=2), mydata, K = numClusters)
   #Leave the rest commented for now
   #output - data.frame(xData, yData, c(as.data.frame(fit[1]),
   as.data.frame(fit[2]), as.data.frame(fit[3])))
   #write.csv - write.table(output, file = output_AP.csv, sep = ,,
   row.names = FALSE, col.names = FALSE)
  
   Here's a call to the script:
  
   $ ./affinity_propagation.R 3
  
   Attaching
  
   The following object is masked package::
  
   heatmap
  
   Trying p = -15.41969
  Number of clusters: 17
   Error in tmpk - K : non-numeric argument to binary operator
   Calls: apclusterK ... apclusterK - .local - apclusterK - apclusterK
 -
   .local
   Execution halted
  
   The line with the expression tmpk - K is from the code for the
   apclusterK() function (from the apcluster library).  The
   definition/value of tmpk is set using a call to the function length().
   I mention this because the failure we're getting with the other script
   also seems to involve an expression with call to length().  Here's the
   error from calling that script:
  
   $ ./spectral_clustering.R 3
   Loading required package: methods
   Error in length(tmpsig) * nc : non-numeric argument to binary operator
   Calls: specc - specc - .local - matrix
   Execution halted
  
   The script is calling the specc() function in the kernlab library.
  
   Any ideas what's going on here, why it's not working and what we can
   do to get it to work?  Is there something that needs to be set or run
   in .Renviron or .Rprofile, say?
  
   Thanks.
  
   Milt Epstein
   Programmer in Computational Genomics
   Institute for