Re: [R-es] resolución de ecuación

2015-10-23 Thread Javier Rubén Marcuzzi
Estimados

Posiblemente algo de lo expuesto en 
https://cran.r-project.org/web/views/Optimization.html pueda ser útil, aunque 
esa ecuación escapa a mi experiencia.

Javier Rubén Marcuzzi
Técnico en Industrias Lácteas
Veterinario



De: Carlos Ortega
Enviado: viernes, 23 de octubre de 2015 8:52
Para: José Miguel Contreras García
CC: r-help-es
Asunto: Re: [R-es] resolución de ecuación


Hola,

Otra alternativia que tienes, por la complejidad de la ecuación que la
tienes expresada como un sumatorio (sin desarrollar) es utilizar "R" unido
al paquete de matemática simbólica "Yacas", mediante "RYacas":

https://cran.r-project.org/web/packages/Ryacas/index.html

Saludos,
Carlos Ortega
www.qualityexcellence.es

El 23 de octubre de 2015, 10:58, José Miguel Contreras García <
jmcontre...@ugr.es> escribió:

> Hola a todos
>
> Tengo una duda existencial, como siempre, jejeje
>
> Quiero resolver una ecuación (F=0) que depende de un parámetro z, pero
> este viene en función de una suma que depende de un vector de tiempos ti
> (1:25) y unos valores de un vector x
>
> Lo he intentado resolver mediante una función para luego utilizar solve,
> pero me he atrancado.
>
> La función es esta:
>
> ti<-1:25
> x<-sample(1:10, size=25, replace=T)
> beta<-0.1
>
> F<-function(z) {
> suma<-0
> for(i in 2:n){
>
> sum<-sum+exp(1)^(-beta*ti[i])/(z-beta)^2*(log(x[i])-exp(1)^(-beta)*log(x[i-1]))*(exp(1)^(ti[i]*(beta-z))*(1-ti[i]*(beta-z))-exp(1)^(-ti[i-1]*(beta-z))*(1-ti[i-1]*(beta-z)))
> }
> }
>
> Quiero calcular el valor de z para que la suma valga cero. ¿He metido
> mucho la pata?
>
> Gracias de antemano
>
> Saludos
>
> ___
> R-help-es mailing list
> R-help-es@r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-help-es
>



-- 
Saludos,
Carlos Ortega
www.qualityexcellence.es

[[alternative HTML version deleted]]

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



[[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] creating a list based on various mean values

2015-10-23 Thread Erin Hodgess
Hello!

I would like to create a list of random values, based on various means.
Here are the potential mean values:

> k1
 [1]  0.005  0.200  0.300  0.400  0.500  0.600  0.700  0.800  0.900  1.000
 1.100  1.200  1.300  1.400
[15]  1.500  1.600  1.700  1.800  1.900  2.000  5.000 10.000

There are 22 of them.

My original thought was to use "do.call" to produce a list of 22 items of
size 20.

> xr <- do.call("rnorm",args=list(n=20,mean=k1))
> xr
 [1] -1.46443269  0.83384389  0.39176720 -0.17954959  0.28245948
-0.44148055  1.98009926  1.73881739
 [9]  1.37312454  1.40509257 -0.03762214  0.43636354  1.82175069
 1.96439065  2.71731752  1.02388062
[17]  1.20732047  3.08650964  0.87910868  0.13018727
>

However, I am just getting back one set of size 20.  What am I doing wrong,
please? Or do I need to do a loop, please?  I thought that there must be a
more elegant solution.

This is on a Macbook Air, R version 3.2.2

Thanks so much,
Sincerely

-- 
Erin Hodgess
Associate Professor
Department of Mathematical and Statistics
University of Houston - Downtown
mailto: erinm.hodg...@gmail.com

[[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] creating a list based on various mean values

2015-10-23 Thread Michael Hannon
Does the following not do what you want?

k1 <- c(0.005, 0.200, 0.300, 0.400, 0.500, 0.600, 0.700, 0.800, 0.900,
1.000, 1.100, 1.200, 1.300, 1.400, 1.500, 1.600, 1.700, 1.800,
1.900, 2.000, 5.000, 10.000)
k1

xr <- lapply(k1, rnorm, n=20)
xr


On Fri, Oct 23, 2015 at 1:51 AM, Erin Hodgess  wrote:
> Hello!
>
> I would like to create a list of random values, based on various means.
> Here are the potential mean values:
>
>> k1
>  [1]  0.005  0.200  0.300  0.400  0.500  0.600  0.700  0.800  0.900  1.000
>  1.100  1.200  1.300  1.400
> [15]  1.500  1.600  1.700  1.800  1.900  2.000  5.000 10.000
>
> There are 22 of them.
>
> My original thought was to use "do.call" to produce a list of 22 items of
> size 20.
>
>> xr <- do.call("rnorm",args=list(n=20,mean=k1))
>> xr
>  [1] -1.46443269  0.83384389  0.39176720 -0.17954959  0.28245948
> -0.44148055  1.98009926  1.73881739
>  [9]  1.37312454  1.40509257 -0.03762214  0.43636354  1.82175069
>  1.96439065  2.71731752  1.02388062
> [17]  1.20732047  3.08650964  0.87910868  0.13018727
>>
>
> However, I am just getting back one set of size 20.  What am I doing wrong,
> please? Or do I need to do a loop, please?  I thought that there must be a
> more elegant solution.
>
> This is on a Macbook Air, R version 3.2.2
>
> Thanks so much,
> Sincerely
>
> --
> Erin Hodgess
> Associate Professor
> Department of Mathematical and Statistics
> University of Houston - Downtown
> mailto: erinm.hodg...@gmail.com
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

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


[R-es] Resolución de ecuación

2015-10-23 Thread jmcontreras

Hola a todos

Tengo una duda existencial, como siempre, jejeje

Quiero resolver una ecuación (F=0) que depende de un parámetro z, pero 
este viene en función de una suma que depende de un vector de tiempos ti 
(1:25) y unos valores de un vector x


Lo he intentado resolver mediante una función para luego utilizar 
solve, pero me he atrancado.


La función es esta:

ti<-1:25
x<-sample(1:10, size=25, replace=T)
beta<-0.1

F<-function(z) {
suma<-0
for(i in 2:n){
sum<-sum+exp(1)^(-beta*ti[i])/(z-beta)^2*(log(x[i])-exp(1)^(-beta)*log(x[i-1]))*(exp(1)^(ti[i]*(beta-z))*(1-ti[i]*(beta-z))-exp(1)^(-ti[i-1]*(beta-z))*(1-ti[i-1]*(beta-z)))
}
}

Quiero calcular el valor de z para que la suma valga cero. ¿He metido 
mucho la pata?


Gracias de antemano

Saludos

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


Re: [R-es] resolución de ecuación

2015-10-23 Thread Carlos Ortega
Hola,

Otra alternativia que tienes, por la complejidad de la ecuación que la
tienes expresada como un sumatorio (sin desarrollar) es utilizar "R" unido
al paquete de matemática simbólica "Yacas", mediante "RYacas":

https://cran.r-project.org/web/packages/Ryacas/index.html

Saludos,
Carlos Ortega
www.qualityexcellence.es

El 23 de octubre de 2015, 10:58, José Miguel Contreras García <
jmcontre...@ugr.es> escribió:

> Hola a todos
>
> Tengo una duda existencial, como siempre, jejeje
>
> Quiero resolver una ecuación (F=0) que depende de un parámetro z, pero
> este viene en función de una suma que depende de un vector de tiempos ti
> (1:25) y unos valores de un vector x
>
> Lo he intentado resolver mediante una función para luego utilizar solve,
> pero me he atrancado.
>
> La función es esta:
>
> ti<-1:25
> x<-sample(1:10, size=25, replace=T)
> beta<-0.1
>
> F<-function(z) {
> suma<-0
> for(i in 2:n){
>
> sum<-sum+exp(1)^(-beta*ti[i])/(z-beta)^2*(log(x[i])-exp(1)^(-beta)*log(x[i-1]))*(exp(1)^(ti[i]*(beta-z))*(1-ti[i]*(beta-z))-exp(1)^(-ti[i-1]*(beta-z))*(1-ti[i-1]*(beta-z)))
> }
> }
>
> Quiero calcular el valor de z para que la suma valga cero. ¿He metido
> mucho la pata?
>
> Gracias de antemano
>
> Saludos
>
> ___
> R-help-es mailing list
> R-help-es@r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-help-es
>



-- 
Saludos,
Carlos Ortega
www.qualityexcellence.es

[[alternative HTML version deleted]]

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


Re: [R] Error in Opening Project on R Studio

2015-10-23 Thread John Kane
There was no attachment so we cannot tell if your problem is an R problem that 
is appropriate for the R-help list or if it is a RStudio issue that should go 
to their help forum.

The R-help list is very fussy about what kinds of attachments that it well 
accept.  It usually is best to just copy and paste any error messages into the 
main text of the e-mail.  If that does not seem appropriate you might try a 
pdf, png or plain text (.txt) attacment.

John Kane
Kingston ON Canada


> -Original Message-
> From: sdee...@iitk.ac.in
> Sent: Thu, 22 Oct 2015 19:48:57 +0530
> To: r-help@r-project.org
> Subject: [R] Error in Opening Project on R Studio
> 
> Good Evening everyone,
>  I am Deepak Singh, Student I.I.T. Kanpur, INDIA, was
> working on a project on R Studio and now when I am
> trying to open my project it is showing the attached
> error. Can it be fixed? if 'Yes' then how can I do
> fix it ? Please help.
> 
> Thank You!
> Deepak Singh
> Student I.I.T. Kanpur, INDIA
> __
> 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.


FREE 3D EARTH SCREENSAVER - Watch the Earth right on your desktop!

__
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] Control of x-axis variable ordering in ggplot

2015-10-23 Thread Hadley Wickham
You have two problems:

* geom_line() always draws from right-to-left
* you're defining colour outside of the plot in a very non-ggplot2 way.

Here's how I'd do it:

library(ggplot2)
data <- data.frame(
  x = rep(1:4, each = 25),
  y = rep(1:25, times = 4),
  g = rep(1:4, each = 25)
)
data$x <- data$x + 0.005 * data$y ^ 2 - 0.1 * data$y + 1

ggplot(data, aes(x, y, colour = factor(g))) +
  geom_point() +
  geom_path()


Alsonotethatcodeismucheasiertoreadifyouusespaces;)

Hadley

On Thu, Oct 22, 2015 at 8:46 PM, sbihorel
 wrote:
> Hi,
>
> Given a certain data.frame, the lattice xyplot function will plot the data
> as.is and join the data point in the order of the data frame. It is my
> (probably flawed) understanding that, using the same data frame, ggplot
> orders the data by increasing order of the x-axis variable. Can one control
> this behavior?
>
> Thanks
>
> Sebastien
>
> Code example
>
> library(lattice)
> library(ggplot2)
>
>
> data <- data.frame(x=rep(1:4,each=25),
>y=rep(1:25,times=4),
>g=rep(1:4,each=25))
> data$x <- data$x + 0.005*(data$y)^2-0.1*data$y+1
>
> col <- 3:7
>
> xyplot(y~x,data=data,groups=g,type='l',col=col)
>
> ggplot(data, aes(x,y,group=g)) + geom_point(colour=col[data$g]) +
>   geom_line(colour=col[data$g])
>
> __
> 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.



-- 
http://had.co.nz/

__
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] Environment question

2015-10-23 Thread Duncan Murdoch
On 23/10/2015 11:08 AM, ALBERTO VIEIRA FERREIRA MONTEIRO wrote:
> From the code below:
> 
> y <- 1
> 
> f1 <- function() { 
>   cat("y =", y, "\n") 
> }
> 
> f2 <- function() { 
>   y <- 2
>   f1()
> }
> 
> f3 <- function() {
>   y <- 3
>   f <- f1
>   f()
> }
> 
> f4 <- function() {
>   y <- 4
>   f <- function() { cat("y =", y, "\n") }
>   f()
> }
> 
> f1()
> f2()
> f3()
> f4()
> 
> Clearly, f1(), f2() and f4() will display "y = 1", "y = 1" and "y = 4",
> but, not as much clearly but predictably, f3() also displays "y = 1".
> 
> Is there any way to rewrite the code of f3 in such a way that it
> displays "y = 3"?

After f <- f1, you can say

environment(f) <- environment()

That says that f should resolve non-local symbols by looking in the
environment that is current in that line, i.e. the local evaluation
frame of this invocation of f3.

One warning:  if in the real use case, the user is supplying f1, then
the user might be giving you something where the environment really
matters, and this substitution would cause the function to return
nonsense.  Or if the user's f1 makes use of other global variables that
happen to have the same name as other locals in f3, nonsense again.

Duncan Murdoch

> 
> An obvious but cumbersome way would be something like:
> 
> f3 <- function() {
>   y <- 3
>   # write the code of f1 to a temporary file
>   dump("f1", "temp.R")
>   # read the code of f1
>   str <- readLines("temp.R")
>   # replace the code that defines function f1 for a code that defines 
> function f
>   str <- gsub("f1 <-", "f <-", str)
>   # write the new code to the temporary file
>   writeLines(str, "temp.R")
>   # read the source but use local to get things from f3's environment
>   # (with the default local = FALSE, "y" would get the value from globalenv())
>   source("temp.R", local = TRUE)
>   # ...?
>   f()
>   # PROFIT!
> }
>   
> Is there a more elegant way to do this?
> 
> Alberto Monteiro
> 
> __
> 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] Environment question

2015-10-23 Thread Bert Gunter
I do not understand exactly what you're looking for: "Any way to
rewrite the code.." is pretty vague. Here is _an_ answer, which may
completely miss what you mean,  followed by some comments.

y <- 1

f1 <- function(x=y) {
  cat("y =", x, "\n")
}

f2 <- function() {
  y <- 2
  f1()
}

f3 <- function() {
  y <- 3
  f1(y)
}

f4 <- function() {
  y <- 4
  f <- function() { cat("y =", y, "\n") }
  f()
}

> f1()
y = 1
> f2()
y = 1
> f3()
y = 3
> f4()
y = 4


Following up on Duncan's comments:

1) Looking up free variables in the enclosing environment is always
potentially risky imo, although it can certainly be useful. Explicitly
passing arguments with defaults seems safer.

2) Explicitly changing the enclosing environment is even riskier, as
Duncan made clear. The "environment<-" Help file explicitly adds:

"The replacement function parent.env<- is extremely dangerous as it
can be used to destructively change environments in ways that violate
assumptions made by the internal C code. It may be removed in the near
future"

If neither Duncan's nor my suggestions are helpful, you might try
re-posting with more context about the specific use case you are
concerned with.

Cheers,
Bert

Bert Gunter

"Data is not information. Information is not knowledge. And knowledge
is certainly not wisdom."
   -- Clifford Stoll


On Fri, Oct 23, 2015 at 8:21 AM, Duncan Murdoch
 wrote:
> On 23/10/2015 11:08 AM, ALBERTO VIEIRA FERREIRA MONTEIRO wrote:
>> From the code below:
>>
>> y <- 1
>>
>> f1 <- function() {
>>   cat("y =", y, "\n")
>> }
>>
>> f2 <- function() {
>>   y <- 2
>>   f1()
>> }
>>
>> f3 <- function() {
>>   y <- 3
>>   f <- f1
>>   f()
>> }
>>
>> f4 <- function() {
>>   y <- 4
>>   f <- function() { cat("y =", y, "\n") }
>>   f()
>> }
>>
>> f1()
>> f2()
>> f3()
>> f4()
>>
>> Clearly, f1(), f2() and f4() will display "y = 1", "y = 1" and "y = 4",
>> but, not as much clearly but predictably, f3() also displays "y = 1".
>>
>> Is there any way to rewrite the code of f3 in such a way that it
>> displays "y = 3"?
>
> After f <- f1, you can say
>
> environment(f) <- environment()
>
> That says that f should resolve non-local symbols by looking in the
> environment that is current in that line, i.e. the local evaluation
> frame of this invocation of f3.
>
> One warning:  if in the real use case, the user is supplying f1, then
> the user might be giving you something where the environment really
> matters, and this substitution would cause the function to return
> nonsense.  Or if the user's f1 makes use of other global variables that
> happen to have the same name as other locals in f3, nonsense again.
>
> Duncan Murdoch
>
>>
>> An obvious but cumbersome way would be something like:
>>
>> f3 <- function() {
>>   y <- 3
>>   # write the code of f1 to a temporary file
>>   dump("f1", "temp.R")
>>   # read the code of f1
>>   str <- readLines("temp.R")
>>   # replace the code that defines function f1 for a code that defines 
>> function f
>>   str <- gsub("f1 <-", "f <-", str)
>>   # write the new code to the temporary file
>>   writeLines(str, "temp.R")
>>   # read the source but use local to get things from f3's environment
>>   # (with the default local = FALSE, "y" would get the value from 
>> globalenv())
>>   source("temp.R", local = TRUE)
>>   # ...?
>>   f()
>>   # PROFIT!
>> }
>>
>> Is there a more elegant way to do this?
>>
>> Alberto Monteiro
>>
>> __
>> 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.


[R] ggplot: combining geom's in function

2015-10-23 Thread sbihorel

Hi,

Next adventure into my journey from lattice to ggplot: I would like to 
create a custom generic function that combines multiple existing geom's  
in order to reproduce what the lattice panel.xyplot function does based 
on the type argument (ie, plotting points only for type='p', plotting 
lines for type 'l', etc).


My current naive attempt is:

library(lattice)
library(ggplot2)

geom_xyplot <- function (mapping = NULL, data = NULL, stat = "identity",
 position = "identity", na.rm = FALSE, type = 
'p', ...) {


  if (any(type=='p')){
geom_point(mapping = mapping, data = data, stat = stat,
   position = position, na.rm = na.rm, ...)
  }
  if (any(type=='l')){
geom_path(mapping = mapping, data = data, stat = stat,
  position = position, na.rm = na.rm, ...)
  }
  if (any(type%in%c('b','o'))){
geom_point(mapping = mapping, data = data, stat = stat,
   position = position, na.rm = na.rm, ...) +
  geom_path(mapping = mapping, data = data, stat = stat,
position = position, na.rm = na.rm, ...)
  }
}

data <- data.frame(x = rep(1:4, each = 25),
   y = rep(1:25, times = 4),
   g = rep(1:4, each = 25))
data$x <- data$x + 0.005*(data$y)^2-0.1*data$y+1

ggplot(data2, aes(x, y, group = g, colour = factor(g))) + 
geom_xyplot(type = 'l')


I get:
> Error: No layers in plot

__
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] resolución de ecuación

2015-10-23 Thread Olivier Nuñez
José, 

varios comentarios: 
1) exp(1)^a =exp(a) 
2) solve es para ecuaciones lineales. La tuya es nolineal 
3) ¿cuales el rango de valores posibles de z? 
4) Prueba la función uniroot.all del paquete "rootSolve". 

Un saludo. Olivier 


- Mensaje original -

De: "José Miguel Contreras García"  
Para: "r-help-es"  
Enviados: Viernes, 23 de Octubre 2015 10:58:06 
Asunto: [R-es] resolución de ecuación 

Hola a todos 

Tengo una duda existencial, como siempre, jejeje 

Quiero resolver una ecuación (F=0) que depende de un parámetro z, pero este 
viene en función de una suma que depende de un vector de tiempos ti (1:25) y 
unos valores de un vector x 

Lo he intentado resolver mediante una función para luego utilizar solve, pero 
me he atrancado. 

La función es esta: 

ti<-1:25 
x<-sample(1:10, size=25, replace=T) 
beta<-0.1 

F<-function(z) { 
suma<-0 
for(i in 2:n){ 
sum<-sum+exp(1)^(-beta*ti[i])/(z-beta)^2*(log(x[i])-exp(1)^(-beta)*log(x[i-1]))*(exp(1)^(ti[i]*(beta-z))*(1-ti[i]*(beta-z))-exp(1)^(-ti[i-1]*(beta-z))*(1-ti[i-1]*(beta-z)))
 
} 
} 

Quiero calcular el valor de z para que la suma valga cero. ¿He metido mucho la 
pata? 

Gracias de antemano 

Saludos 
___ 
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-es] resolución de ecuación

2015-10-23 Thread José Miguel Contreras García
Hola a todos

Tengo una duda existencial, como siempre, jejeje

Quiero resolver una ecuación (F=0) que depende de un parámetro z, pero este 
viene en función de una suma que depende de un vector de tiempos ti (1:25) y 
unos valores de un vector x

Lo he intentado resolver mediante una función para luego utilizar solve, pero 
me he atrancado.

La función es esta:

ti<-1:25
x<-sample(1:10, size=25, replace=T) 
beta<-0.1

F<-function(z) {
suma<-0
for(i in 2:n){
sum<-sum+exp(1)^(-beta*ti[i])/(z-beta)^2*(log(x[i])-exp(1)^(-beta)*log(x[i-1]))*(exp(1)^(ti[i]*(beta-z))*(1-ti[i]*(beta-z))-exp(1)^(-ti[i-1]*(beta-z))*(1-ti[i-1]*(beta-z)))
}
} 

Quiero calcular el valor de z para que la suma valga cero. ¿He metido mucho la 
pata?

Gracias de antemano

Saludos

smime.p7s
Description: S/MIME cryptographic signature
___
R-help-es mailing list
R-help-es@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-help-es

[R-es] resolución de ecuación

2015-10-23 Thread José Miguel Contreras García
Hola a todosTengo una duda existencial, como siempre, jejejeQuiero resolver una ecuación (F=0) que depende de un parámetro z, pero este viene en función de una suma que depende de un vector de tiempos ti (1:25) y unos valores de un vector xLo he intentado resolver mediante una función para luego utilizar solve, pero me he atrancado.La función es esta:ti<-1:25x<-sample(1:10, size=25, replace=T) beta<-0.1F<-function(z) {suma<-0for(i in 2:n){sum<-sum+exp(1)^(-beta*ti[i])/(z-beta)^2*(log(x[i])-exp(1)^(-beta)*log(x[i-1]))*(exp(1)^(ti[i]*(beta-z))*(1-ti[i]*(beta-z))-exp(1)^(-ti[i-1]*(beta-z))*(1-ti[i-1]*(beta-z)))}} Quiero calcular el valor de z para que la suma valga cero. ¿He metido mucho la pata?Gracias de antemanoSaludos
___
R-help-es mailing list
R-help-es@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-help-es

Re: [R] virus/trojan in contributed package: 'svs'

2015-10-23 Thread peter dalgaard
Virus scanners generate a fair amount of false positives. Does it persist if 
you unpack the zip file or the source tarball? If so, what file has the issue?

-pd

On 23 Oct 2015, at 09:38 , Bijoy Joseph  wrote:

> Hello,
> 
> I came across the following when I was installing the 'svs' package:
> 
> $ clamscan svs_1.0.3.zip
> svs_1.0.3.zip: BAT.CMDFlood FOUND
> 
> --- SCAN SUMMARY ---
> Known viruses: 4035827
> Engine version: 0.98.7
> Scanned directories: 0
> Scanned files: 1
> Infected files: 1
> 
> 
> clamscan finds this trojan in the source tarball as well. Does the r-project 
> does a virus scan of contributed packages? I had come across a virus a few 
> years earlier, but an email to the maintainer fixed that issue. I have heard 
> nothing (yet) from the maintainer in this case.
> 
> Bijoy
> 
> __
> 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.

-- 
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] annotating faceted ggplot

2015-10-23 Thread efisio solazzo
Dear, I have been reading several posts but still cannot work out how to 
annotate a faceted boxplot created from existing statistics using ggplot.


the dataframe is smthing like:


dep_stat

  specie.sp. models min max   q25q50  q75
1NO2   mod1   0   225.0   0.1   0.401.300
2NO2   mod2   0   219.5   0.6   2.408.100
3 O3   mod1   0  2834.4  93.8 334.80  793.525
4 O3   mod2   0  1238.6   5.0 214.70  376.400
5   PM25   mod1   0 49948.0 123.5 438.10 1146.100
6   PM25   mod2   0  2466.1   9.2  24.55  184.300


from which I create the plot in the figure, where the bars go from min 
to the 75th percentile.


ggplot(dep_stat, aes(x=models, ymin=min, ymax=q75, lower=q25, 
middle=q50, upper=q75)) +

geom_boxplot(stat='identity', width=0.5) +
theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1.5)) +
theme(axis.title.x = element_blank())+theme(axis.title.y = 
element_blank()) +

facet_wrap(~specie.sp., nrow=1, scales="free")

I'm trying to add (as text) at the top of each bar the maximum value, 
but the annotate command doesn't do the job right:


annotate('text', x=rep(seq(1:length(models)),3), y=q75+0.5, 
label=as.character(max), color="red", angle = 90, cex=5).


In this way three values text get added to each column...I have also 
tried with geom_text and grobTree, without success.


thanks for your help.



__
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] ggplot: combining geom's in function

2015-10-23 Thread Erich Neuwirth
I often look for examples in
http://www.cookbook-r.com/Graphs/ 

> On 23 Oct 2015, at 18:27, Jeff Newmiller  wrote:
> 
> Have you looked at the qplot function in the ggplot2 package?
> ---
> Jeff NewmillerThe .   .  Go Live...
> DCN:Basics: ##.#.   ##.#.  Live Go...
>  Live:   OO#.. Dead: OO#..  Playing
> Research Engineer (Solar/BatteriesO.O#.   #.O#.  with
> /Software/Embedded Controllers)   .OO#.   .OO#.  rocks...1k
> ---
> Sent from my phone. Please excuse my brevity.
> 
> On October 23, 2015 3:12:41 PM GMT+02:00, sbihorel 
>  wrote:
>> Hi,
>> 
>> Next adventure into my journey from lattice to ggplot: I would like to
>> create a custom generic function that combines multiple existing geom's
>> 
>> in order to reproduce what the lattice panel.xyplot function does based
>> 
>> on the type argument (ie, plotting points only for type='p', plotting
>> lines for type 'l', etc).
>> 
>> My current naive attempt is:
>> 
>> library(lattice)
>> library(ggplot2)
>> 
>> geom_xyplot <- function (mapping = NULL, data = NULL, stat =
>> "identity",
>> position = "identity", na.rm = FALSE, type =
>> 'p', ...) {
>> 
>>  if (any(type=='p')){
>>geom_point(mapping = mapping, data = data, stat = stat,
>>   position = position, na.rm = na.rm, ...)
>>  }
>>  if (any(type=='l')){
>>geom_path(mapping = mapping, data = data, stat = stat,
>>  position = position, na.rm = na.rm, ...)
>>  }
>>  if (any(type%in%c('b','o'))){
>>geom_point(mapping = mapping, data = data, stat = stat,
>>   position = position, na.rm = na.rm, ...) +
>>  geom_path(mapping = mapping, data = data, stat = stat,
>>position = position, na.rm = na.rm, ...)
>>  }
>> }
>> 
>> data <- data.frame(x = rep(1:4, each = 25),
>>   y = rep(1:25, times = 4),
>>   g = rep(1:4, each = 25))
>> data$x <- data$x + 0.005*(data$y)^2-0.1*data$y+1
>> 
>> ggplot(data2, aes(x, y, group = g, colour = factor(g))) +
>> geom_xyplot(type = 'l')
>> 
>> I get:
>>> Error: No layers in plot
>> 
>> __
>> 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.



signature.asc
Description: Message signed with OpenPGP using GPGMail
__
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] Control of x-axis variable ordering in ggplot

2015-10-23 Thread sbihorel

Hi,

I want to thank Jeff, Dennis, c06n, and Hadley for their replies and 
explanations. As you probably guessed, I am fairly new to ggplot am 
trying to loose my lattice reflex while transitioning to ggplot.


Thank for the link to the ggplot external documentation.

Sebastien

On 10/23/2015 7:15 AM, Hadley Wickham wrote:

You have two problems:

* geom_line() always draws from right-to-left
* you're defining colour outside of the plot in a very non-ggplot2 way.

Here's how I'd do it:

library(ggplot2)
data <- data.frame(
   x = rep(1:4, each = 25),
   y = rep(1:25, times = 4),
   g = rep(1:4, each = 25)
)
data$x <- data$x + 0.005 * data$y ^ 2 - 0.1 * data$y + 1

ggplot(data, aes(x, y, colour = factor(g))) +
   geom_point() +
   geom_path()


Alsonotethatcodeismucheasiertoreadifyouusespaces;)

Hadley

On Thu, Oct 22, 2015 at 8:46 PM, sbihorel
 wrote:

Hi,

Given a certain data.frame, the lattice xyplot function will plot the data
as.is and join the data point in the order of the data frame. It is my
(probably flawed) understanding that, using the same data frame, ggplot
orders the data by increasing order of the x-axis variable. Can one control
this behavior?

Thanks

Sebastien

Code example

library(lattice)
library(ggplot2)


data <- data.frame(x=rep(1:4,each=25),
y=rep(1:25,times=4),
g=rep(1:4,each=25))
data$x <- data$x + 0.005*(data$y)^2-0.1*data$y+1

col <- 3:7

xyplot(y~x,data=data,groups=g,type='l',col=col)

ggplot(data, aes(x,y,group=g)) + geom_point(colour=col[data$g]) +
   geom_line(colour=col[data$g])

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





--
Sebastien Bihorel
Cognigen Corporation
(t) +1 716 633 3463 ext 323
Cognigen Corporation, a wholly owned subsidiary of Simulations Plus, Inc.
__
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] elementwise matrix multiplication with a special structure

2015-10-23 Thread eugen pircalabelu via R-help
Hello R users,
I have the following annoying matrix multiplication and I do not know how to 
avoid the nested loops, so maybe someone can help me with some ideas. I have 
searched the forum for past posts but nothing came up.Here it is:
 aa=matrix(1:9,3,3) bb=matrix(seq(10,90,by=10),3,3) cc=matrix(seq(100,900, 
by=100),3,3) dd=NULL 
for(r in 1:3){for(c in 1:3){for(j in 1:3){for(k in 
1:3){dd=c(dd,aa[j,k]*bb[r,j]*cc[k,c])dd [1]   1000   8000  21000   8000  
4  96000  21000  84000 189000   4000[11]  2  42000  32000 10 192000 
 84000 21 378000   7000  32000[21]  63000  56000 16 288000 147000 
336000 567000   2000  16000  42000[31]  1  5 12  24000  96000 
216000   8000  4  84000  4[41] 125000 24  96000 24 432000  
14000  64000 126000  7 20[51] 36 168000 384000 648000   3000  24000 
 63000  12000  6 144000[61]  27000 108000 243000  12000  6 126000  
48000 15 288000 108000[71] 27 486000  21000  96000 189000  84000 24 
432000 189000 432000[81] 729000
What I want to obtain is the content of the vector dd in an efficient (fast) 
and clever way.Thank you very much and have a great day ahead!Eugen

[[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] ggplot: combining geom's in function

2015-10-23 Thread Jeff Newmiller
Have you looked at the qplot function in the ggplot2 package?
---
Jeff NewmillerThe .   .  Go Live...
DCN:Basics: ##.#.   ##.#.  Live Go...
  Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/BatteriesO.O#.   #.O#.  with
/Software/Embedded Controllers)   .OO#.   .OO#.  rocks...1k
--- 
Sent from my phone. Please excuse my brevity.

On October 23, 2015 3:12:41 PM GMT+02:00, sbihorel 
 wrote:
>Hi,
>
>Next adventure into my journey from lattice to ggplot: I would like to 
>create a custom generic function that combines multiple existing geom's
> 
>in order to reproduce what the lattice panel.xyplot function does based
>
>on the type argument (ie, plotting points only for type='p', plotting 
>lines for type 'l', etc).
>
>My current naive attempt is:
>
>library(lattice)
>library(ggplot2)
>
>geom_xyplot <- function (mapping = NULL, data = NULL, stat =
>"identity",
>  position = "identity", na.rm = FALSE, type = 
>'p', ...) {
>
>   if (any(type=='p')){
> geom_point(mapping = mapping, data = data, stat = stat,
>position = position, na.rm = na.rm, ...)
>   }
>   if (any(type=='l')){
> geom_path(mapping = mapping, data = data, stat = stat,
>   position = position, na.rm = na.rm, ...)
>   }
>   if (any(type%in%c('b','o'))){
> geom_point(mapping = mapping, data = data, stat = stat,
>position = position, na.rm = na.rm, ...) +
>   geom_path(mapping = mapping, data = data, stat = stat,
> position = position, na.rm = na.rm, ...)
>   }
>}
>
>data <- data.frame(x = rep(1:4, each = 25),
>y = rep(1:25, times = 4),
>g = rep(1:4, each = 25))
>data$x <- data$x + 0.005*(data$y)^2-0.1*data$y+1
>
>ggplot(data2, aes(x, y, group = g, colour = factor(g))) + 
>geom_xyplot(type = 'l')
>
>I get:
> > Error: No layers in plot
>
>__
>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] virus/trojan in contributed package: 'svs'

2015-10-23 Thread Bijoy Joseph

See output below:

$ clamscan -ri svs/
./svs/extdata/InvT_Eng.txt: BAT.CMDFlood FOUND

In the tarball, the file is "./inst/extdata/InvT_Eng.txt", and clamscan 
gives the same output.


$ file svs/extdata/InvT_Eng.txt
./svs/extdata/InvT_Eng.txt: ASCII text, with CRLF line terminators

I managed to find a Windows machine to scan the file (using MS System 
center Endpoint), and it detected no threat! False positive, as you 
suggested.


Thanks,
Bijoy Joseph


On 2015-10-23 12:23, peter dalgaard wrote:

Virus scanners generate a fair amount of false positives. Does it persist if 
you unpack the zip file or the source tarball? If so, what file has the issue?

-pd

On 23 Oct 2015, at 09:38 , Bijoy Joseph  wrote:


Hello,

I came across the following when I was installing the 'svs' package:

$ clamscan svs_1.0.3.zip
svs_1.0.3.zip: BAT.CMDFlood FOUND

--- SCAN SUMMARY ---
Known viruses: 4035827
Engine version: 0.98.7
Scanned directories: 0
Scanned files: 1
Infected files: 1


clamscan finds this trojan in the source tarball as well. Does the r-project 
does a virus scan of contributed packages? I had come across a virus a few 
years earlier, but an email to the maintainer fixed that issue. I have heard 
nothing (yet) from the maintainer in this case.

Bijoy

__
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] Control of x-axis variable ordering in ggplot

2015-10-23 Thread c06n
Hi,

are you trying to do the same thing with ggplot as with lattice? 

In this case, your solution looks probably like this: 

ggplot(data, aes(x, y, group = g)) + 
  geom_path(aes(colour = g))

If you haven’t done so yet, I strongly recommend reading through the ggplot2 
documentation: http://docs.ggplot2.org/current/index.html 


It’s a bit of a read, but you’ll need this knowledge to successfully operate 
ggplot.

> Am 23.10.2015 um 03:46 schrieb sbihorel :
> 
> Hi,
> 
> Given a certain data.frame, the lattice xyplot function will plot the data 
> as.is and join the data point in the order of the data frame. It is my 
> (probably flawed) understanding that, using the same data frame, ggplot 
> orders the data by increasing order of the x-axis variable. Can one control 
> this behavior?
> 
> Thanks
> 
> Sebastien
> 
> Code example
> 
> library(lattice)
> library(ggplot2)
> 
> 
> data <- data.frame(x=rep(1:4,each=25),
>   y=rep(1:25,times=4),
>   g=rep(1:4,each=25))
> data$x <- data$x + 0.005*(data$y)^2-0.1*data$y+1
> 
> col <- 3:7
> 
> xyplot(y~x,data=data,groups=g,type='l',col=col)
> 
> ggplot(data, aes(x,y,group=g)) + geom_point(colour=col[data$g]) +
>  geom_line(colour=col[data$g])
> 
> __
> 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] JSONlite import problem

2015-10-23 Thread K. Elo

Hi!

You can download the example file with this link:
https://www.dropbox.com/s/tlf1gkym6d83log/example.json?dl=0

BTW, I have used a JSON validator and the problem seems to related to 
wrong/missing EOF.


--- snip ---
Error: Parse error on line 1:
...:"1436705823768"} {"created_at":"Sun J
-^
Expecting 'EOF', '}', ',', ']', got '{'
--- snip ---

However, editing the file with a text editor to create "proper" EOF 
doesn't help.


-Kimmo-

23.10.2015, 22:52, Duncan Murdoch wrote:

It looks like it's the same sort of problem as in that stackoverflow
posting:  what's in your file is not valid Javascript, so it's not valid
JSON.  It's probably multiple JSON objects without proper separators;
you need to do the separating yourself.

BTW, your attachment failed; only some file types are allowed.  You
should probably put the file online somewhere and post the URL.

Duncan Murdoch


__
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 correct documentation?

2015-10-23 Thread Ming-Lun Ho
Hi,
I used "?mtcars" to read the documentation for the dataset. I found a
mistake in how unit is listed, namely, that for the variable "wt," the unit
should be listed as "1000 lb," not "lb/1000." However, I don't know whom to
contact exactly for the correction. Please point me to the right place.
Thanks.
  --Ming

[[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] elementwise matrix multiplication with a special structure

2015-10-23 Thread David L Carlson
Don't use html formatted emails. The r-help server strips the html formatting 
leaving us the the mess you see below. 

You don't need any loops:

> aa <- matrix(1:9, 3, 3)
> bb <- aa * 10
> cc <- bb * 10
> x <- as.matrix(expand.grid(k=1:3, j=1:3, c=1:3, r=1:3))
> str(x)
 int [1:81, 1:4] 1 2 3 1 2 3 1 2 3 1 ...
 - attr(*, "dimnames")=List of 2
  ..$ : NULL
  ..$ : chr [1:4] "k" "j" "c" "r"
> dd <- aa[x[, c("j", "k")]] * bb[x[, c("r", "j")]] * cc[x[, c("k", "c")]]
> dd
 [1]   1000   8000  21000   8000  4  96000  21000  84000 189000
[10]   4000  2  42000  32000 10 192000  84000 21 378000
[19]   7000  32000  63000  56000 16 288000 147000 336000 567000
[28]   2000  16000  42000  1  5 12  24000  96000 216000
[37]   8000  4  84000  4 125000 24  96000 24 432000
[46]  14000  64000 126000  7 20 36 168000 384000 648000
[55]   3000  24000  63000  12000  6 144000  27000 108000 243000
[64]  12000  6 126000  48000 15 288000 108000 27 486000
[73]  21000  96000 189000  84000 24 432000 189000 432000 729000

# Or a bit more compactly
> dd <- aa[x[, c(2, 1)]] * bb[x[, c(4, 2)]] * cc[x[, c(1, 3)]]

-
David L Carlson
Department of Anthropology
Texas A University
College Station, TX 77840-4352



-Original Message-
From: R-help [mailto:r-help-boun...@r-project.org] On Behalf Of eugen 
pircalabelu via R-help
Sent: Friday, October 23, 2015 12:31 PM
To: r-help@r-project.org
Subject: [R] elementwise matrix multiplication with a special structure

Hello R users,
I have the following annoying matrix multiplication and I do not know how to 
avoid the nested loops, so maybe someone can help me with some ideas. I have 
searched the forum for past posts but nothing came up.Here it is:
 aa=matrix(1:9,3,3) bb=matrix(seq(10,90,by=10),3,3) cc=matrix(seq(100,900, 
by=100),3,3) dd=NULL 
for(r in 1:3){for(c in 1:3){for(j in 1:3){for(k in 
1:3){dd=c(dd,aa[j,k]*bb[r,j]*cc[k,c])dd [1]   1000   8000  21000   8000  
4  96000  21000  84000 189000   4000[11]  2  42000  32000 10 192000 
 84000 21 378000   7000  32000[21]  63000  56000 16 288000 147000 
336000 567000   2000  16000  42000[31]  1  5 12  24000  96000 
216000   8000  4  84000  4[41] 125000 24  96000 24 432000  
14000  64000 126000  7 20[51] 36 168000 384000 648000   3000  24000 
 63000  12000  6 144000[61]  27000 108000 243000  12000  6 126000  
48000 15 288000 108000[71] 27 486000  21000  96000 189000  84000 24 
432000 189000 432000[81] 729000
What I want to obtain is the content of the vector dd in an efficient (fast) 
and clever way.Thank you very much and have a great day ahead!Eugen

[[alternative HTML version deleted]]

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

[R] JSONlite import problem

2015-10-23 Thread K. Elo

Hi!

I have collected 500.000+ tweets with a Python script using 'tweepy', 
which stored the data in JSON format. I would like to use R for data 
analysis, but have encountered problems when trying to import the data 
file with 'jsonlite'.


Here what I have tried:

> data.df<-fromJSON("example.json")
Error in feed_push_parser(readBin(con, raw(), n), reset = TRUE) :
  parse error: trailing garbage
  stamp_ms":"1436705823768"}   {"created_at":"Sun Jul 12 12:57
 (right here) --^

The import fails already on the first line :( A sample file causing this 
error is attached.


I have tried several solutions, e.g. this:
http://stackoverflow.com/questions/26519455/error-parsing-json-file-with-the-jsonlite-package

but it does not work and results in the same error.

Could anyone help me to understand what is causing the error and how to 
solve the issue? Thanks in advance.


Kind regards,
Kimmo Elo

--
University of Turku, Finland
Dep. of political science and contemporary history
__
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] ggplot: combining geom's in function

2015-10-23 Thread sbihorel

Hi

Thanks for the suggestion. Unfortunately, the qplot function would work 
nicely if only I did not need to combine its output with other geom 
called before...


A simple example using the data previously described:

ggplot(data, aes(x,y,group=g)) + geom_blank() + 
qplot(x=x,y=y,data=data,group=g,colour=factor(g),geom = c('point','line'))

> Error in p + o : non-numeric argument to binary operator
In addition: Warning message:
Incompatible methods ("+.gg", "Ops.data.frame") for "+"

I know I could combine the geom's by adapting the order of the calls to 
my data and needs for this one example. But this is not my goal. I am 
trying to build a generic function, not an ad-hoc script.


Sebastien

On 10/23/2015 12:27 PM, Jeff Newmiller wrote:

Have you looked at the qplot function in the ggplot2 package?
---
Jeff NewmillerThe .   .  Go Live...
DCN:Basics: ##.#.   ##.#.  Live Go...
   Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/BatteriesO.O#.   #.O#.  with
/Software/Embedded Controllers)   .OO#.   .OO#.  rocks...1k
---
Sent from my phone. Please excuse my brevity.

On October 23, 2015 3:12:41 PM GMT+02:00, sbihorel 
 wrote:

Hi,

Next adventure into my journey from lattice to ggplot: I would like to
create a custom generic function that combines multiple existing geom's

in order to reproduce what the lattice panel.xyplot function does based

on the type argument (ie, plotting points only for type='p', plotting
lines for type 'l', etc).

My current naive attempt is:

library(lattice)
library(ggplot2)

geom_xyplot <- function (mapping = NULL, data = NULL, stat =
"identity",
  position = "identity", na.rm = FALSE, type =
'p', ...) {

   if (any(type=='p')){
 geom_point(mapping = mapping, data = data, stat = stat,
position = position, na.rm = na.rm, ...)
   }
   if (any(type=='l')){
 geom_path(mapping = mapping, data = data, stat = stat,
   position = position, na.rm = na.rm, ...)
   }
   if (any(type%in%c('b','o'))){
 geom_point(mapping = mapping, data = data, stat = stat,
position = position, na.rm = na.rm, ...) +
   geom_path(mapping = mapping, data = data, stat = stat,
 position = position, na.rm = na.rm, ...)
   }
}

data <- data.frame(x = rep(1:4, each = 25),
y = rep(1:25, times = 4),
g = rep(1:4, each = 25))
data$x <- data$x + 0.005*(data$y)^2-0.1*data$y+1

ggplot(data2, aes(x, y, group = g, colour = factor(g))) +
geom_xyplot(type = 'l')

I get:

Error: No layers in plot

__
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] ggplot: combining geom's in function

2015-10-23 Thread sbihorel
Following up on my previous reply, this following would work but would 
not behave like a geom function:


geom_xyplot <- function (gplot, mapping = NULL, data = NULL, stat = 
"identity",
 position = "identity", na.rm = FALSE, type = 
'p', ...) {


  if (any(type=='p')){
gplot + geom_point(mapping = mapping, data = data, stat = stat,
   position = position, na.rm = na.rm, ...)
  }
  if (any(type=='l')){
gplot + geom_path(mapping = mapping, data = data, stat = stat,
  position = position, na.rm = na.rm, ...)
  }
  if (any(type%in%c('b','o'))){
gplot + geom_point(mapping = mapping, data = data, stat = stat,
   position = position, na.rm = na.rm, ...) +
  geom_path(mapping = mapping, data = data, stat = stat,
position = position, na.rm = na.rm, ...)
  }
}

Sebastien

On 10/23/2015 12:27 PM, Jeff Newmiller wrote:

Have you looked at the qplot function in the ggplot2 package?
---
Jeff NewmillerThe .   .  Go Live...
DCN:Basics: ##.#.   ##.#.  Live Go...
   Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/BatteriesO.O#.   #.O#.  with
/Software/Embedded Controllers)   .OO#.   .OO#.  rocks...1k
---
Sent from my phone. Please excuse my brevity.

On October 23, 2015 3:12:41 PM GMT+02:00, sbihorel 
 wrote:

Hi,

Next adventure into my journey from lattice to ggplot: I would like to
create a custom generic function that combines multiple existing geom's

in order to reproduce what the lattice panel.xyplot function does based

on the type argument (ie, plotting points only for type='p', plotting
lines for type 'l', etc).

My current naive attempt is:

library(lattice)
library(ggplot2)

geom_xyplot <- function (mapping = NULL, data = NULL, stat =
"identity",
  position = "identity", na.rm = FALSE, type =
'p', ...) {

   if (any(type=='p')){
 geom_point(mapping = mapping, data = data, stat = stat,
position = position, na.rm = na.rm, ...)
   }
   if (any(type=='l')){
 geom_path(mapping = mapping, data = data, stat = stat,
   position = position, na.rm = na.rm, ...)
   }
   if (any(type%in%c('b','o'))){
 geom_point(mapping = mapping, data = data, stat = stat,
position = position, na.rm = na.rm, ...) +
   geom_path(mapping = mapping, data = data, stat = stat,
 position = position, na.rm = na.rm, ...)
   }
}

data <- data.frame(x = rep(1:4, each = 25),
y = rep(1:25, times = 4),
g = rep(1:4, each = 25))
data$x <- data$x + 0.005*(data$y)^2-0.1*data$y+1

ggplot(data2, aes(x, y, group = g, colour = factor(g))) +
geom_xyplot(type = 'l')

I get:

Error: No layers in plot

__
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] string split problem

2015-10-23 Thread Jun Shen
Hi Marc/Bill
Thanks for reply. That's exactly what I am looking for.
Jun

On Fri, Oct 23, 2015 at 3:53 PM, William Dunlap  wrote:

> > test <- c('aaa.bb.cc','aaa.dd', 'aaa', 'aaa.', '.eee', '')
> > sub("([^.]*)(.*)", "\\1", test)
> [1] "aaa" "aaa" "aaa" "aaa" """"
> > sub("([^.]*)(.*)", "\\2", test)
> [1] ".bb.cc" ".dd"""   "."  ".eee"   ""
> Bill Dunlap
> TIBCO Software
> wdunlap tibco.com
>
>
> On Fri, Oct 23, 2015 at 12:17 PM, Jun Shen  wrote:
> > Dear list,
> >
> > Say I have a vector that has two different types of string
> >
> > test <- c('aaa.bb.cc','aaa.dd')
> >
> > I want to extract the first part of the string (aaa) as a name and save
> the
> > rest of the string as another name.
> >
> > I was thinking something like
> >
> > sub('(.*)\\.(.*)','\\1',test) but doesn't give me what I want.
> >
> >
> > Appreciate any comments. Thanks.
> >
> > Jun
> >
> > [[alternative HTML version deleted]]
> >
> > __
> > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> > https://stat.ethz.ch/mailman/listinfo/r-help
> > PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> > and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

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


[R] string split problem

2015-10-23 Thread Jun Shen
Dear list,

Say I have a vector that has two different types of string

test <- c('aaa.bb.cc','aaa.dd')

I want to extract the first part of the string (aaa) as a name and save the
rest of the string as another name.

I was thinking something like

sub('(.*)\\.(.*)','\\1',test) but doesn't give me what I want.


Appreciate any comments. Thanks.

Jun

[[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] string split problem

2015-10-23 Thread William Dunlap
> test <- c('aaa.bb.cc','aaa.dd', 'aaa', 'aaa.', '.eee', '')
> sub("([^.]*)(.*)", "\\1", test)
[1] "aaa" "aaa" "aaa" "aaa" """"
> sub("([^.]*)(.*)", "\\2", test)
[1] ".bb.cc" ".dd"""   "."  ".eee"   ""
Bill Dunlap
TIBCO Software
wdunlap tibco.com


On Fri, Oct 23, 2015 at 12:17 PM, Jun Shen  wrote:
> Dear list,
>
> Say I have a vector that has two different types of string
>
> test <- c('aaa.bb.cc','aaa.dd')
>
> I want to extract the first part of the string (aaa) as a name and save the
> rest of the string as another name.
>
> I was thinking something like
>
> sub('(.*)\\.(.*)','\\1',test) but doesn't give me what I want.
>
>
> Appreciate any comments. Thanks.
>
> Jun
>
> [[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] JSONlite import problem

2015-10-23 Thread Duncan Murdoch

On 23/10/2015 3:44 PM, K. Elo wrote:

Hi!

I have collected 500.000+ tweets with a Python script using 'tweepy',
which stored the data in JSON format. I would like to use R for data
analysis, but have encountered problems when trying to import the data
file with 'jsonlite'.

Here what I have tried:

  > data.df<-fromJSON("example.json")
Error in feed_push_parser(readBin(con, raw(), n), reset = TRUE) :
parse error: trailing garbage
stamp_ms":"1436705823768"}   {"created_at":"Sun Jul 12 12:57
   (right here) --^

The import fails already on the first line :( A sample file causing this
error is attached.

I have tried several solutions, e.g. this:
http://stackoverflow.com/questions/26519455/error-parsing-json-file-with-the-jsonlite-package

but it does not work and results in the same error.

Could anyone help me to understand what is causing the error and how to
solve the issue? Thanks in advance.


It looks like it's the same sort of problem as in that stackoverflow 
posting:  what's in your file is not valid Javascript, so it's not valid 
JSON.  It's probably multiple JSON objects without proper separators; 
you need to do the separating yourself.


BTW, your attachment failed; only some file types are allowed.  You 
should probably put the file online somewhere and post the URL.


Duncan Murdoch

__
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] string split problem

2015-10-23 Thread Marc Schwartz

> On Oct 23, 2015, at 2:17 PM, Jun Shen  wrote:
> 
> Dear list,
> 
> Say I have a vector that has two different types of string
> 
> test <- c('aaa.bb.cc','aaa.dd')
> 
> I want to extract the first part of the string (aaa) as a name and save the
> rest of the string as another name.
> 
> I was thinking something like
> 
> sub('(.*)\\.(.*)','\\1',test) but doesn't give me what I want.
> 
> 
> Appreciate any comments. Thanks.
> 
> Jun


How about something like this, which presumes that the characters (besides the 
periods) are only letters:

> gsub("^([[:alpha:]]+)\\.(.*)$", "\\1|\\2", test) 
[1] "aaa|bb.cc" "aaa|dd"   

or

> sub("^([[:alpha:]]+)\\.(.*)$", "\\1|\\2", test) 
[1] "aaa|bb.cc" "aaa|dd"   


The above takes the two components, before and after the first '.', adds the 
"|" as a character in between, to then be used in strsplit():


> strsplit(gsub("^([[:alpha:]]+)\\.(.*)$", "\\1|\\2", test), split = "\\|") 
[[1]]
[1] "aaa"   "bb.cc"

[[2]]
[1] "aaa" "dd" 


See ?regex

Regards,

Marc Schwartz

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


[R] Environment question

2015-10-23 Thread ALBERTO VIEIRA FERREIRA MONTEIRO
>From the code below:

y <- 1

f1 <- function() { 
  cat("y =", y, "\n") 
}

f2 <- function() { 
  y <- 2
  f1()
}

f3 <- function() {
  y <- 3
  f <- f1
  f()
}

f4 <- function() {
  y <- 4
  f <- function() { cat("y =", y, "\n") }
  f()
}

f1()
f2()
f3()
f4()

Clearly, f1(), f2() and f4() will display "y = 1", "y = 1" and "y = 4",
but, not as much clearly but predictably, f3() also displays "y = 1".

Is there any way to rewrite the code of f3 in such a way that it
displays "y = 3"?

An obvious but cumbersome way would be something like:

f3 <- function() {
  y <- 3
  # write the code of f1 to a temporary file
  dump("f1", "temp.R")
  # read the code of f1
  str <- readLines("temp.R")
  # replace the code that defines function f1 for a code that defines function f
  str <- gsub("f1 <-", "f <-", str)
  # write the new code to the temporary file
  writeLines(str, "temp.R")
  # read the source but use local to get things from f3's environment
  # (with the default local = FALSE, "y" would get the value from globalenv())
  source("temp.R", local = TRUE)
  # ...?
  f()
  # PROFIT!
}
  
Is there a more elegant way to do this?

Alberto Monteiro

__
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] Applying ME in spdep to phylogenetic autocorrelation

2015-10-23 Thread Megan Bartlett
Hi all,

I want to fit a model with the form:

trait 1 ~ trait 2 + environmental variable

while controlling for the phylogenetic relatedness in my study species. I
would use phylogenetic least squares regression, but I want to apply an
independent effects analysis to partition the effects of trait 2 and
environment on trait 1. (Partial correlation doesn't work here since all 3
variables are correlated).

It looks like the ME function in the spdep package does exactly what I
would like to do for phylogenetic autocorrelation, but for spatial
autocorrelation. Is there a way to apply ME to phylogenetically structured
instead of spatially structured data? I can use the mat2listw function to
convert the phylogenetic distance matrix to a listw object, but I'm not
sure I'm representing the neighbor relationships correctly. Should each
taxa be connected to every other taxa by a weight that reflects the
phylogenetic distance, or should only the most closely related tips be
counted as neighbors? Should the phylogenetic distance matrix itself go
into the mat2listw function, or should the values be converted to
1/distance, to be analogous to spatial weights? How can I use the S0, S1,
and S2 values from the summary() of the listw object to figure out whether
I've represented the neighbors correctly?

Thanks very much for your help!

Best,

Megan Bartlett

[[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] virus/trojan in contributed package: 'svs'

2015-10-23 Thread Bijoy Joseph

Hello,

I came across the following when I was installing the 'svs' package:

$ clamscan svs_1.0.3.zip
svs_1.0.3.zip: BAT.CMDFlood FOUND

--- SCAN SUMMARY ---
Known viruses: 4035827
Engine version: 0.98.7
Scanned directories: 0
Scanned files: 1
Infected files: 1


clamscan finds this trojan in the source tarball as well. Does the 
r-project does a virus scan of contributed packages? I had come across a 
virus a few years earlier, but an email to the maintainer fixed that 
issue. I have heard nothing (yet) from the maintainer in this case.


Bijoy

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