Re: [R-es] Como puedo reducir el tiempo de ejecución en la siguiente rutina

2020-12-13 Thread Emilio L. Cano
Hola,

Para la primera parte (seleccionar los valores más altos de una variable) yo 
usaría dplyr::slice_max(). Creo que eso debería ser rápido y con el filtro 
hecho lo demás debería ser trivial. Si he entendido bien el problema.

Un saludo,
Emilio

> El 13 dic 2020, a las 15:31, Carlos Santos  
> escribió:
> 
> Perdón Carlos, con las prisas se me olvidó por completo añadir lo que 
> faltaba, tienes toda la razón
> 
> Supongamos que tenemos esta matriz, se quiere conseguir para el mayor valor 
> por fila tomar el valor de la posición que ocupa la primera columna "Var" en 
> base a la columna elegida y si hay varios valores máximos iguales, entonces 
> ejecutar la función "f5" para elegir una y según valor máximo obtenido 
> proceder de la misma manera que antes.
> 
> El problema es cuando tengo matrices de 3000x3000 o 1x1, y además los 
> dígitos de la columna primera son superiores al puesto en este ejemplo, 
> entonces el tiempo de calculo es excesivo.
> 
> 
> 
> codigo:
>  
> f5 <- function(x){data1 %>% filter(Clus.Multi.OPTIMO %in% 
> c(EMISOR,RECEPTOR[x])) %>%
> dplyr::select(1:numvar+1) %>% data.matrix() %>% CohenD()}
> #
> #
> fila = 1
> rr = nrow(data2)
> data1 <- data1 %>% mutate(Clus.Multi.OPTIMO=Clus.Multi.MAX)  
> #
> repeat{
> smc <- 
> sum(data2[fila,((2+fila):(nrow(data2)+2))]==max(data2[fila,((2+fila):(nrow(data2)+2))]))
> EMISOR <- data2[fila,1]$Var
> RECEPTOR <- 
> data2[which(as.vector(t(data2[fila,])[,1])==max(data2[fila,((2+fila):(nrow(data2)+2))]))-2,1]$Var
> Rmax <- RECEPTOR[mclapply((1:smc),f5) %>% unlist() %>% which.max()]
> data1$Clus.Multi.OPTIMO[which(data1$Clus.Multi.MAX == data2[fila,1]$Var)] 
> <- Rmax
> fila = fila + 1
> if (fila == rr) {break}
> }
>  
> 
> 
>  
> 
> Libre de virus. www.avast.com 
> 
>  
> El dom, 13 dic 2020 a las 12:49, Carlos Ortega ( >) escribió:
> Hola,
> 
> Mejor si pones un ejemplo de tu matriz y cuentas lo que quieres hacer...
> El  enfoque puede ser muy diferente al que has planteado.
> 
> Gracias,
> Calros Ortega
> www.qualityexcellence.es 
> 
> El dom, 13 dic 2020 a las 12:33, Carlos Santos ( >) escribió:
> Buen dia,
> 
> Tengo un problema cuando ejecuto la siguiente rutina, porque con una matriz
> muy grande el tiempo de ejecución se va a bastantes  horas.
> 
> Cualquier idea para mejorarlo y reducir significativamente el tiempo,
> estaría muy agradecido
> 
> Muchas gracias por vuestra ayuda
> 
> #_
> 
> f5 <- function(x){data1 %>% filter(Clus.Multi.OPTIMO %in%
> c(EMISOR,RECEPTOR[x])) %>%
> dplyr::select(1:numvar+1) %>% data.matrix() %>% CohenD()}
> 
> #
> __
> 
> fila = 1
> rr = nrow(data2)
> 
> repeat{
> smc <-
> sum(data2[fila,((2+fila):(nrow(data2)+2))]==max(data2[fila,((2+fila):(nrow(data2)+2))]))
> EMISOR <- data2[fila,1]$Var
> RECEPTOR <-
> data2[which(as.vector(t(data2[fila,])[,1])==max(data2[fila,((2+fila):(nrow(data2)+2))]))-2,1]$Var
> 
> Rmax <- RECEPTOR[mclapply((1:smc),f5) %>% unlist() %>% which.max()]
> 
> data1$Clus.Multi.OPTIMO[which(data1$Clus.Multi.MAX ==
>  data2[fila,1]$Var)] <- Rmax
> fila = fila + 1
> if (fila == rr) {break}
> }
> 
>   
> >
> Libre
> de virus. www.avast.com 
>   
> >
> <#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>
> 
> [[alternative HTML version deleted]]
> 
> ___
> 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 
> ___
> R-help-es mailing list
> R-help-es@r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-help-es


[[alternative HTML version deleted]]

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


Re: [R] How to specify year-month-day for a plot

2020-12-13 Thread Jeff Newmiller
Bill pointed out some errors in your code but you keep making the claim that 
-MM-DD is not recognized and I just want to make it completely clear that 
that is the default format for dates in R as it is an ISO standard. So focus on 
other issues until you get it working... this format is definitely not your 
problem.

On December 13, 2020 5:34:45 PM PST, Gregory Coats via R-help 
 wrote:
>Hi Jim,
>Thank you VERY much!
>In what I tried, my values for the vertical Y were automatically
>understood by R.
>But it appears that the string -mm-dd was NOT recognized by R as a
>date for the X axis, and gave a red error message.
>My values for Year-Month-Day were NOT understood by R.
>Is there a convenient way to tell R to interpret “2020-12-13” as a
>date?
>
>data <- data.frame(
>day = as.Date("2020-02-15", "2020-03-10", "2020-05-04", "2020-06-21",
>"2020-08-01", "2020-08-27", "2020-09-28", "2020-11-09", "2020-12-11")
>value = (15.973, 18.832, 17.392, 14.774, 19.248, 14.913, 15.226,
>14.338, 18.777, 19.652))
>p <- ggplot(data, aes(x=day, y=value))
>  geom_line()
>  xlab("X Label")
>p
>Error: unexpected symbol in:
>"  day = as.Date("2020-02-15", "2020-03-10", "2020-05-04",
>"2020-06-21", "2020-08-01", "2020-08-27", "2020-09-28", "2020-11-09",
>"2020-12-11")
>  value"
>
>Greg Coats
>gregco...@me.com
>Reston, Virginia USA
>
>> On Dec 13, 2020, at 5:42 PM, Jim Lemon  wrote:
>> 
>> Hi Gregory,
>> Here's a start:
>> 
>> gcdf<-read.table(text="2020-01-05 15.973
>> 2020-02-15 18.832
>> 2020-03-10 17.392
>> 2020-05-04 14.774
>> 2020-06-21 19.248
>> 2020-08-01 14.913
>> 2020-08-27 15.226
>> 2020-09-28 14.338
>> 2020-11-09 18.777
>> 2020-12-11 19.652",
>> header=TRUE,stringsAsFactors=FALSE,
>> col.names=c("date","gallons"))
>> gcdf$date<-as.Date(gcdf$date,"%Y-%m-%d")
>> plot(gcdf$date,gcdf$gallons,main="Gallons by date",
>> xlab="Date",ylab="Gallons")
>> 
>> Jim
>> 
>> On Mon, Dec 14, 2020 at 9:33 AM Gregory Coats via R-help
>>  wrote:
>>> 
>>> Starting with year-month-day, for the variable gallons, I can easily
>plot the variable gallons, while disregarding the date.
>>> gallons <- c (15.973, 18.832, 17.392, 14.774, 19.248, 14.913,
>15.226, 14.338, 18.777, 19.652)
>>> plot (gallons, type="l", xlab="X label", ylab="Y label", col="blue”)
>>> 
>>> How do I direct R to plot the variable gallons, at the appropriate,
>irregularly-spaced places on the X axis, while paying attention to the
>year-month-day?
>>> 
>>> format = "%Y-%m-%d”
>>> 2020-01-05 15.973
>>> 2020-02-15 18.832
>>> 2020-03-10 17.392
>>> 2020-05-04 14.774
>>> 2020-06-21 19.248
>>> 2020-08-01 14.913
>>> 2020-08-27 15.226
>>> 2020-09-28 14.338
>>> 2020-11-09 18.777
>>> 2020-12-11 19.652
>>>[[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.

-- 
Sent from my phone. Please excuse my brevity.

__
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] A question on substitute()

2020-12-13 Thread Bert Gunter
Please disregard my previous post. My understanding is correct, and the
behavior is **AS DOCUMENTED**.
I failed to read the docs carefully. Mea Culpa.

Best,
Bert

Bert Gunter

"The trouble with having an open mind is that people keep coming along and
sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )


On Sun, Dec 13, 2020 at 8:32 PM Bert Gunter  wrote:

> I would appreciate any help in correcting my misunderstanding of the
> following:
>
> > substitute(quote(x+a), env = list(a=5))
> quote(x + 5)  ## as expected
> > substitute(quote(x+a), env = list2env(list(a=5)))
> quote(x + 5)  ## as expected
>
> > ### BUT
> > .GlobalEnv$a
> [1] 5
> > substitute(quote(x+a), env = .GlobalEnv)
> quote(x + a)  ## unexpected
>
> I conclude from this that there is something special about .GlobalEnv that
> does not allow it to behave as documented for the env argument in
> ?substitute, to wit:
>
> "env:
>
> an environment or a list object. Defaults to the current evaluation
> environment."
>
> I would be grateful for any insight, as I am clearly missing something.
>
>
> Note: (though I don't think this matters):
>
> > sessionInfo()
> R version 4.0.3 (2020-10-10)
> Platform: x86_64-apple-darwin17.0 (64-bit)
> Running under: macOS Big Sur 10.16
>
>
> Cheers to all,
>
> Bert
>
> Bert Gunter
>
> "The trouble with having an open mind is that people keep coming along and
> sticking things into it."
> -- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )
>

[[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] A question on substitute()

2020-12-13 Thread Bert Gunter
I would appreciate any help in correcting my misunderstanding of the
following:

> substitute(quote(x+a), env = list(a=5))
quote(x + 5)  ## as expected
> substitute(quote(x+a), env = list2env(list(a=5)))
quote(x + 5)  ## as expected

> ### BUT
> .GlobalEnv$a
[1] 5
> substitute(quote(x+a), env = .GlobalEnv)
quote(x + a)  ## unexpected

I conclude from this that there is something special about .GlobalEnv that
does not allow it to behave as documented for the env argument in
?substitute, to wit:

"env:

an environment or a list object. Defaults to the current evaluation
environment."

I would be grateful for any insight, as I am clearly missing something.


Note: (though I don't think this matters):

> sessionInfo()
R version 4.0.3 (2020-10-10)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Big Sur 10.16


Cheers to all,

Bert

Bert Gunter

"The trouble with having an open mind is that people keep coming along and
sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )

[[alternative HTML version deleted]]

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


Re: [R] How to specify year-month-day for a plot

2020-12-13 Thread Jim Lemon
Hi Gregory,

On Mon, Dec 14, 2020 at 12:34 PM Gregory Coats  wrote:
>...
> Is there a convenient way to tell R to interpret “2020-12-13” as a date?
>
Notice the as.Date command in the code I sent to you. this converts a
string to a date with a resolution of one day. If you want a higher
time resolution, use strptime or one of the other POSIX date
conversion functions.

Jim

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


Re: [R] How to specify year-month-day for a plot

2020-12-13 Thread Bill Dunlap
You left out some calls to c().  Note that
   (2,3,5)
is not valid syntax for making a vector of numbers; use
   c(2,3,5)
You also left out a comma and gave different lengths for day and value.
You also left out plus signs between the various components of your ggplot
expression.

Try
 data <- data.frame(
 day = as.Date(c("2020-02-15", "2020-03-10", "2020-05-04",
"2020-06-21", "2020-08-01", "2020-08-27", "2020-09-28", "2020-11-09",
"2020-12-11", "2020-12-12")),
 value = c(15.973, 18.832, 17.392, 14.774, 19.248, 14.913, 15.226,
14.338, 18.777, 19.652))

 p <- ggplot(data, aes(x=day, y=value))+
   geom_line()+
   xlab("X Label")
 p

On Sun, Dec 13, 2020 at 5:35 PM Gregory Coats via R-help <
r-help@r-project.org> wrote:

> Hi Jim,
> Thank you VERY much!
> In what I tried, my values for the vertical Y were automatically
> understood by R.
> But it appears that the string -mm-dd was NOT recognized by R as a
> date for the X axis, and gave a red error message.
> My values for Year-Month-Day were NOT understood by R.
> Is there a convenient way to tell R to interpret “2020-12-13” as a date?
>
> data <- data.frame(
>   day = as.Date("2020-02-15", "2020-03-10", "2020-05-04", "2020-06-21",
> "2020-08-01", "2020-08-27", "2020-09-28", "2020-11-09", "2020-12-11")
>   value = (15.973, 18.832, 17.392, 14.774, 19.248, 14.913, 15.226, 14.338,
> 18.777, 19.652))
> p <- ggplot(data, aes(x=day, y=value))
>   geom_line()
>   xlab("X Label")
> p
> Error: unexpected symbol in:
> "  day = as.Date("2020-02-15", "2020-03-10", "2020-05-04", "2020-06-21",
> "2020-08-01", "2020-08-27", "2020-09-28", "2020-11-09", "2020-12-11")
>   value"
>
> Greg Coats
> gregco...@me.com
> Reston, Virginia USA
>
> > On Dec 13, 2020, at 5:42 PM, Jim Lemon  wrote:
> >
> > Hi Gregory,
> > Here's a start:
> >
> > gcdf<-read.table(text="2020-01-05 15.973
> > 2020-02-15 18.832
> > 2020-03-10 17.392
> > 2020-05-04 14.774
> > 2020-06-21 19.248
> > 2020-08-01 14.913
> > 2020-08-27 15.226
> > 2020-09-28 14.338
> > 2020-11-09 18.777
> > 2020-12-11 19.652",
> > header=TRUE,stringsAsFactors=FALSE,
> > col.names=c("date","gallons"))
> > gcdf$date<-as.Date(gcdf$date,"%Y-%m-%d")
> > plot(gcdf$date,gcdf$gallons,main="Gallons by date",
> > xlab="Date",ylab="Gallons")
> >
> > Jim
> >
> > On Mon, Dec 14, 2020 at 9:33 AM Gregory Coats via R-help
> >  wrote:
> >>
> >> Starting with year-month-day, for the variable gallons, I can easily
> plot the variable gallons, while disregarding the date.
> >> gallons <- c (15.973, 18.832, 17.392, 14.774, 19.248, 14.913, 15.226,
> 14.338, 18.777, 19.652)
> >> plot (gallons, type="l", xlab="X label", ylab="Y label", col="blue”)
> >>
> >> How do I direct R to plot the variable gallons, at the appropriate,
> irregularly-spaced places on the X axis, while paying attention to the
> year-month-day?
> >>
> >> format = "%Y-%m-%d”
> >> 2020-01-05 15.973
> >> 2020-02-15 18.832
> >> 2020-03-10 17.392
> >> 2020-05-04 14.774
> >> 2020-06-21 19.248
> >> 2020-08-01 14.913
> >> 2020-08-27 15.226
> >> 2020-09-28 14.338
> >> 2020-11-09 18.777
> >> 2020-12-11 19.652
> >>[[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.
>

[[alternative HTML version deleted]]

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


Re: [R] How to specify year-month-day for a plot

2020-12-13 Thread Gregory Coats via R-help
Hi Jim,
Thank you VERY much!
In what I tried, my values for the vertical Y were automatically understood by 
R.
But it appears that the string -mm-dd was NOT recognized by R as a date for 
the X axis, and gave a red error message.
My values for Year-Month-Day were NOT understood by R.
Is there a convenient way to tell R to interpret “2020-12-13” as a date?

data <- data.frame(
  day = as.Date("2020-02-15", "2020-03-10", "2020-05-04", "2020-06-21", 
"2020-08-01", "2020-08-27", "2020-09-28", "2020-11-09", "2020-12-11")
  value = (15.973, 18.832, 17.392, 14.774, 19.248, 14.913, 15.226, 14.338, 
18.777, 19.652))
p <- ggplot(data, aes(x=day, y=value))
  geom_line()
  xlab("X Label")
p
Error: unexpected symbol in:
"  day = as.Date("2020-02-15", "2020-03-10", "2020-05-04", "2020-06-21", 
"2020-08-01", "2020-08-27", "2020-09-28", "2020-11-09", "2020-12-11")
  value"

Greg Coats
gregco...@me.com
Reston, Virginia USA

> On Dec 13, 2020, at 5:42 PM, Jim Lemon  wrote:
> 
> Hi Gregory,
> Here's a start:
> 
> gcdf<-read.table(text="2020-01-05 15.973
> 2020-02-15 18.832
> 2020-03-10 17.392
> 2020-05-04 14.774
> 2020-06-21 19.248
> 2020-08-01 14.913
> 2020-08-27 15.226
> 2020-09-28 14.338
> 2020-11-09 18.777
> 2020-12-11 19.652",
> header=TRUE,stringsAsFactors=FALSE,
> col.names=c("date","gallons"))
> gcdf$date<-as.Date(gcdf$date,"%Y-%m-%d")
> plot(gcdf$date,gcdf$gallons,main="Gallons by date",
> xlab="Date",ylab="Gallons")
> 
> Jim
> 
> On Mon, Dec 14, 2020 at 9:33 AM Gregory Coats via R-help
>  wrote:
>> 
>> Starting with year-month-day, for the variable gallons, I can easily plot 
>> the variable gallons, while disregarding the date.
>> gallons <- c (15.973, 18.832, 17.392, 14.774, 19.248, 14.913, 15.226, 
>> 14.338, 18.777, 19.652)
>> plot (gallons, type="l", xlab="X label", ylab="Y label", col="blue”)
>> 
>> How do I direct R to plot the variable gallons, at the appropriate, 
>> irregularly-spaced places on the X axis, while paying attention to the 
>> year-month-day?
>> 
>> format = "%Y-%m-%d”
>> 2020-01-05 15.973
>> 2020-02-15 18.832
>> 2020-03-10 17.392
>> 2020-05-04 14.774
>> 2020-06-21 19.248
>> 2020-08-01 14.913
>> 2020-08-27 15.226
>> 2020-09-28 14.338
>> 2020-11-09 18.777
>> 2020-12-11 19.652
>>[[alternative HTML version deleted]]
>> __
>> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.


[[alternative HTML version deleted]]

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


Re: [R] ggplot2 + coord_cartesian + automatic ylim

2020-12-13 Thread Brian Beckage
David,

Great suggestion!

Thanks,
Brian






On Dec 13, 2020, at 6:06 PM, David Winsemius 
mailto:dwinsem...@comcast.net>> wrote:


On 12/13/20 12:49 PM, Brian Beckage wrote:
As an example to illustrate my question, if I used the following code to plot 
the price of Apple stock using the tidyquant package and ggplot2


AAPL<-tq_get(x="AAPL")

AAPL %>%
  ggplot(aes(x = date, y = close)) +
  geom_line() +
  labs(title = "AAPL", y = "Closing Price", x = "") +
  coord_x_date(xlim=c(end-weeks(10),end),ylim=c(100,150)) +
  theme_tq()

but I would like the ylim to be set automatically based on the xlim.  In base 
R, this is a simple thing to do. ggplot is still a bit mysterious to me (not 
alway clear how it works) and so I would like to automatically set the ylim 
range based on the xlim range,  something  like the following, though it 
obviously does not work:


AAPL<-tq_get(x="AAPL")

AAPL %>%
  ggplot(aes(x = date, y = close)) +
  geom_line() +
  labs(title = "AAPL Line Chart", y = "Closing Price", x = "") +
  coord_x_date(xlim=c(end-weeks(10),end),ylim=c(min(y),max(y)) +
  theme_tq()

where the y vector corresponds to the y range delimited by xlim.  Note that 
coord_x_date is a wrapper for coord_cartesian.


Why not let ggplot do it for you by "filtering" the data down to the date range 
you expect.


AAPL %>% filter(date > end-weeks(10)) %>%
ggplot(aes(x = date, y = close)) +
geom_line() +
labs(title = "AAPL", y = "Closing Price", x = "") +
coord_x_date(xlim=c(end-weeks(10),end)) +
theme_tq()


Might not even need `coord_x_date` call at all.


So how do I ’see’ and use the data and parms being utilized by ggplot to set 
the ylim?  Or more generally, how do you step through code like to this to 
examine for instance what exactly coord_x_date is doing?

Thanks,
Brian







[[alternative HTML version deleted]]

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

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


[[alternative HTML version deleted]]

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


Re: [R] ggplot2 + coord_cartesian + automatic ylim

2020-12-13 Thread Daniel Nordlund

On 12/13/2020 12:49 PM, Brian Beckage wrote:

As an example to illustrate my question, if I used the following code to plot 
the price of Apple stock using the tidyquant package and ggplot2


AAPL<-tq_get(x="AAPL")

AAPL %>%
   ggplot(aes(x = date, y = close)) +
   geom_line() +
   labs(title = "AAPL", y = "Closing Price", x = "") +
   coord_x_date(xlim=c(end-weeks(10),end),ylim=c(100,150)) +
   theme_tq()

but I would like the ylim to be set automatically based on the xlim.  In base 
R, this is a simple thing to do. ggplot is still a bit mysterious to me (not 
alway clear how it works) and so I would like to automatically set the ylim 
range based on the xlim range,  something  like the following, though it 
obviously does not work:


AAPL<-tq_get(x="AAPL")

AAPL %>%
   ggplot(aes(x = date, y = close)) +
   geom_line() +
   labs(title = "AAPL Line Chart", y = "Closing Price", x = "") +
   coord_x_date(xlim=c(end-weeks(10),end),ylim=c(min(y),max(y)) +
   theme_tq()

where the y vector corresponds to the y range delimited by xlim.  Note that 
coord_x_date is a wrapper for coord_cartesian.

So how do I ’see’ and use the data and parms being utilized by ggplot to set 
the ylim?  Or more generally, how do you step through code like to this to 
examine for instance what exactly coord_x_date is doing?

Thanks,
Brian







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


Brian,

I couldn't get your code to work, so I modified it slightly. Someone 
more adept at ggplot than me may be able to give you a better solution.


xmax<-AAPL$date[nrow(AAPL)]
xminmax <- c(xmax-weeks(10), xmax)
yminmax <- with(AAPL, range(AAPL[date>=xmin & date<=xmax,]$close))

AAPL %>%
  ggplot(aes(x = date, y = close)) +
  geom_line() +
  labs(title = "AAPL", y = "Closing Price", x = "") +
  coord_x_date(xlim=xminmax, ylim=yminmax) +
  theme_tq()


Hope this is helpful,

Dan

--
Daniel Nordlund
Port Townsend, WA  USA

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


Re: [R] multiple t-test with different species and treatments

2020-12-13 Thread Bert Gunter
1. Please read and follow the posting guide linked below.
2. No html -- this is a plain text list.
3. Use ?dput to provide us your data so that we don't have to convert it
for you.
4. We expect you to first make an effort to do your own coding. See
?t.test, which you could also
have found yourself by a web search (rseek.org is a reasonable place to
search from for R-related stuff,
though I have usually found that a plain google search does the job).
5. Is this homework? -- this list has a no homework policy (see the posting
guide).

Bert Gunter

"The trouble with having an open mind is that people keep coming along and
sticking things into it."
-- Opus (aka Berkeley Breathed in his "Bloom County" comic strip )


On Sun, Dec 13, 2020 at 2:33 PM Lingling Wen 
wrote:

> Dear R users,
> I would like to ask for help with the code of multiple t-test. I have a
> dataset as followed:
> Species Treatment var1 var2 var2 var4 var5 var6
> Blue D 0.022620093 0.125079631 0.04522571 0.010105835 0.013418019
> 1.455646741
> Blue D 0.02117295 0.073544277 0.0311234 0.008742305 0.03261776 0.982196898
> Blue D 0.021896521 0.112681274 0.05664344 0.013512548 0.032380618
> 1.777003683
> Green D 0.032749726 0.087705198 0.13699174 0.009902168 0.083534492
> 1.553758965
> Green D 0.036468693 0.115829755 0.10941521 0.012139481 0.206929915
> 2.610557732
> Green D 0.043594022 0.062832712 0.12232853 0.015045559 0.111687593
> 1.99552401
> Orange D 0.022617656 0.11465489 0.02882994 0.013304181 0.018175693
> 1.72075866
> Orange D 0.026211773 0.099294867 0.03387876 0.013408254 0.02971197
> 2.184955376
> Orange D 0.032205662 0.057267709 0.03883165 0.007744362 0.026553323
> 1.27255601
> White D 0.041135469 0.085531343 0.06921425 0.011496168 0.010196895
> 0.573205411
> White D 0.045142458 0.111429194 0.03546278 0.009196729 0.009968818
> 0.748529991
> White D 0.031471913 0.050175149 0.05233851 0.011447205 0.010424973
> 0.92385457
> Blue W 0.02296 0.112334911 0.04080824 0.016064488 0.031047157
> 0.885523847
> Blue W 0.040238733 0.121941307 0.04239768 0.010310538 0.020106944
> 0.751643349
> Blue W 0.031508947 0.131547704 0.05212774 0.015720985 0.013932284
> 0.881234886
> Green W 0.021070032 0.121018603 0.38202466 0.022152283 0.038479532
> 0.662605036
> Green W 0.026562365 0.108269047 0.44028708 0.019344875 0.090798566
> 0.746330971
> Green W 0.02926478 0.084080729 0.32376224 0.012609717 0.097744041
> 0.969301308
> Orange W 0.02456562 0.134535891 0.09135624 0.007701481 0.017310058
> 0.966322354
> Orange W 0.032095541 0.149347595 0.06048885 0.010332579 0.017457175
> 0.561561725
> Orange W 0.039120696 0.141941743 0.02962146 0.005889924 0.017162941
> 0.502529091
> White W 0.033903057 0.061460583 0.0492955 0.012457767 0.029929334
> 0.70986421
> White W 0.033630233 0.115782233 0.02675399 0.021391535 0.023774961
> 1.176680075
> White W 0.030638581 0.065074112 0.03678494 0.014781912 0.03529703
> 0.805500558
> I wanted to perform a t-test between the treatment "D" and "W" of each
> species for all of the variables (var1, var2,...).  Could anyone suggest
> the packages or code for this analysis?
>
> [[alternative HTML version deleted]]
>
> __
> R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

[[alternative HTML version deleted]]

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


Re: [R] How to specify year-month-day for a plot

2020-12-13 Thread Jeff Newmiller
By converting the character date data into a time-like type... e.g. ?as.Date 
and plotting y-vs-x.

On December 12, 2020 11:18:46 AM PST, Gregory Coats via R-help 
 wrote:
>Starting with year-month-day, for the variable gallons, I can easily
>plot the variable gallons, while disregarding the date. 
>gallons <- c (15.973, 18.832, 17.392, 14.774, 19.248, 14.913, 15.226,
>14.338, 18.777, 19.652)
>plot (gallons, type="l", xlab="X label", ylab="Y label", col="blue”)
>
>How do I direct R to plot the variable gallons, at the appropriate,
>irregularly-spaced places on the X axis, while paying attention to the
>year-month-day?
>
>format = "%Y-%m-%d”
>2020-01-05 15.973
>2020-02-15 18.832
>2020-03-10 17.392
>2020-05-04 14.774
>2020-06-21 19.248
>2020-08-01 14.913
>2020-08-27 15.226
>2020-09-28 14.338
>2020-11-09 18.777
>2020-12-11 19.652
>   [[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.

-- 
Sent from my phone. Please excuse my brevity.

__
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] ggplot2 + coord_cartesian + automatic ylim

2020-12-13 Thread David Winsemius



On 12/13/20 12:49 PM, Brian Beckage wrote:

As an example to illustrate my question, if I used the following code to plot 
the price of Apple stock using the tidyquant package and ggplot2


AAPL<-tq_get(x="AAPL")

AAPL %>%
   ggplot(aes(x = date, y = close)) +
   geom_line() +
   labs(title = "AAPL", y = "Closing Price", x = "") +
   coord_x_date(xlim=c(end-weeks(10),end),ylim=c(100,150)) +
   theme_tq()

but I would like the ylim to be set automatically based on the xlim.  In base 
R, this is a simple thing to do. ggplot is still a bit mysterious to me (not 
alway clear how it works) and so I would like to automatically set the ylim 
range based on the xlim range,  something  like the following, though it 
obviously does not work:


AAPL<-tq_get(x="AAPL")

AAPL %>%
   ggplot(aes(x = date, y = close)) +
   geom_line() +
   labs(title = "AAPL Line Chart", y = "Closing Price", x = "") +
   coord_x_date(xlim=c(end-weeks(10),end),ylim=c(min(y),max(y)) +
   theme_tq()

where the y vector corresponds to the y range delimited by xlim.  Note that 
coord_x_date is a wrapper for coord_cartesian.



Why not let ggplot do it for you by "filtering" the data down to the 
date range you expect.



AAPL %>% filter(date > end-weeks(10)) %>%
    ggplot(aes(x = date, y = close)) +
    geom_line() +
    labs(title = "AAPL", y = "Closing Price", x = "") +
    coord_x_date(xlim=c(end-weeks(10),end)) +
    theme_tq()


Might not even need `coord_x_date` call at all.



So how do I ’see’ and use the data and parms being utilized by ggplot to set 
the ylim?  Or more generally, how do you step through code like to this to 
examine for instance what exactly coord_x_date is doing?

Thanks,
Brian







[[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] How to specify year-month-day for a plot

2020-12-13 Thread Jim Lemon
Hi Gregory,
Here's a start:

gcdf<-read.table(text="2020-01-05 15.973
2020-02-15 18.832
2020-03-10 17.392
2020-05-04 14.774
2020-06-21 19.248
2020-08-01 14.913
2020-08-27 15.226
2020-09-28 14.338
2020-11-09 18.777
2020-12-11 19.652",
header=TRUE,stringsAsFactors=FALSE,
col.names=c("date","gallons"))
gcdf$date<-as.Date(gcdf$date,"%Y-%m-%d")
plot(gcdf$date,gcdf$gallons,main="Gallons by date",
xlab="Date",ylab="Gallons")

Jim

On Mon, Dec 14, 2020 at 9:33 AM Gregory Coats via R-help
 wrote:
>
> Starting with year-month-day, for the variable gallons, I can easily plot the 
> variable gallons, while disregarding the date.
> gallons <- c (15.973, 18.832, 17.392, 14.774, 19.248, 14.913, 15.226, 14.338, 
> 18.777, 19.652)
> plot (gallons, type="l", xlab="X label", ylab="Y label", col="blue”)
>
> How do I direct R to plot the variable gallons, at the appropriate, 
> irregularly-spaced places on the X axis, while paying attention to the 
> year-month-day?
>
> format = "%Y-%m-%d”
> 2020-01-05 15.973
> 2020-02-15 18.832
> 2020-03-10 17.392
> 2020-05-04 14.774
> 2020-06-21 19.248
> 2020-08-01 14.913
> 2020-08-27 15.226
> 2020-09-28 14.338
> 2020-11-09 18.777
> 2020-12-11 19.652
> [[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] multiple t-test with different species and treatments

2020-12-13 Thread Lingling Wen
Dear R users,
I would like to ask for help with the code of multiple t-test. I have a
dataset as followed:
Species Treatment var1 var2 var2 var4 var5 var6
Blue D 0.022620093 0.125079631 0.04522571 0.010105835 0.013418019
1.455646741
Blue D 0.02117295 0.073544277 0.0311234 0.008742305 0.03261776 0.982196898
Blue D 0.021896521 0.112681274 0.05664344 0.013512548 0.032380618
1.777003683
Green D 0.032749726 0.087705198 0.13699174 0.009902168 0.083534492
1.553758965
Green D 0.036468693 0.115829755 0.10941521 0.012139481 0.206929915
2.610557732
Green D 0.043594022 0.062832712 0.12232853 0.015045559 0.111687593
1.99552401
Orange D 0.022617656 0.11465489 0.02882994 0.013304181 0.018175693
1.72075866
Orange D 0.026211773 0.099294867 0.03387876 0.013408254 0.02971197
2.184955376
Orange D 0.032205662 0.057267709 0.03883165 0.007744362 0.026553323
1.27255601
White D 0.041135469 0.085531343 0.06921425 0.011496168 0.010196895
0.573205411
White D 0.045142458 0.111429194 0.03546278 0.009196729 0.009968818
0.748529991
White D 0.031471913 0.050175149 0.05233851 0.011447205 0.010424973
0.92385457
Blue W 0.02296 0.112334911 0.04080824 0.016064488 0.031047157
0.885523847
Blue W 0.040238733 0.121941307 0.04239768 0.010310538 0.020106944
0.751643349
Blue W 0.031508947 0.131547704 0.05212774 0.015720985 0.013932284
0.881234886
Green W 0.021070032 0.121018603 0.38202466 0.022152283 0.038479532
0.662605036
Green W 0.026562365 0.108269047 0.44028708 0.019344875 0.090798566
0.746330971
Green W 0.02926478 0.084080729 0.32376224 0.012609717 0.097744041
0.969301308
Orange W 0.02456562 0.134535891 0.09135624 0.007701481 0.017310058
0.966322354
Orange W 0.032095541 0.149347595 0.06048885 0.010332579 0.017457175
0.561561725
Orange W 0.039120696 0.141941743 0.02962146 0.005889924 0.017162941
0.502529091
White W 0.033903057 0.061460583 0.0492955 0.012457767 0.029929334 0.70986421
White W 0.033630233 0.115782233 0.02675399 0.021391535 0.023774961
1.176680075
White W 0.030638581 0.065074112 0.03678494 0.014781912 0.03529703
0.805500558
I wanted to perform a t-test between the treatment "D" and "W" of each
species for all of the variables (var1, var2,...).  Could anyone suggest
the packages or code for this analysis?

[[alternative HTML version deleted]]

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


[R] How to specify year-month-day for a plot

2020-12-13 Thread Gregory Coats via R-help
Starting with year-month-day, for the variable gallons, I can easily plot the 
variable gallons, while disregarding the date. 
gallons <- c (15.973, 18.832, 17.392, 14.774, 19.248, 14.913, 15.226, 14.338, 
18.777, 19.652)
plot (gallons, type="l", xlab="X label", ylab="Y label", col="blue”)

How do I direct R to plot the variable gallons, at the appropriate, 
irregularly-spaced places on the X axis, while paying attention to the 
year-month-day?

format = "%Y-%m-%d”
2020-01-05 15.973
2020-02-15 18.832
2020-03-10 17.392
2020-05-04 14.774
2020-06-21 19.248
2020-08-01 14.913
2020-08-27 15.226
2020-09-28 14.338
2020-11-09 18.777
2020-12-11 19.652
[[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] ggplot2 + coord_cartesian + automatic ylim

2020-12-13 Thread Brian Beckage
As an example to illustrate my question, if I used the following code to plot 
the price of Apple stock using the tidyquant package and ggplot2


AAPL<-tq_get(x="AAPL")

AAPL %>%
  ggplot(aes(x = date, y = close)) +
  geom_line() +
  labs(title = "AAPL", y = "Closing Price", x = "") +
  coord_x_date(xlim=c(end-weeks(10),end),ylim=c(100,150)) +
  theme_tq()

but I would like the ylim to be set automatically based on the xlim.  In base 
R, this is a simple thing to do. ggplot is still a bit mysterious to me (not 
alway clear how it works) and so I would like to automatically set the ylim 
range based on the xlim range,  something  like the following, though it 
obviously does not work:


AAPL<-tq_get(x="AAPL")

AAPL %>%
  ggplot(aes(x = date, y = close)) +
  geom_line() +
  labs(title = "AAPL Line Chart", y = "Closing Price", x = "") +
  coord_x_date(xlim=c(end-weeks(10),end),ylim=c(min(y),max(y)) +
  theme_tq()

where the y vector corresponds to the y range delimited by xlim.  Note that 
coord_x_date is a wrapper for coord_cartesian.

So how do I ’see’ and use the data and parms being utilized by ggplot to set 
the ylim?  Or more generally, how do you step through code like to this to 
examine for instance what exactly coord_x_date is doing?

Thanks,
Brian







[[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] Como puedo reducir el tiempo de ejecución en la siguiente rutina

2020-12-13 Thread Carlos Ortega
Hola Carlos,

Vaya, lo siento pero creo que me sigue faltando algo para entenderlo todo...

1. Tienes una primera matriz en la que por fila tienes que elegir la
columna en la que se produce el máximo.
2. Pero si hay dos/o varios valores de máximo, tienes que coger el valor de
"Var" de esa primera matriz y buscarla en la segunda matriz (la imagen que
adjunta) y seleccionar la columna de acuerdo a f5...

Si pones un ejemplo donde haya un único valor de máximo y otro donde hay
que usar esta f5, quedaría ya del todo claro...

Gracias,
Carlos Ortega
www.qualityexcellence.es

El dom, 13 dic 2020 a las 15:31, Carlos Santos ()
escribió:

> Perdón Carlos, con las prisas se me olvidó por completo añadir lo que
>> faltaba, tienes toda la razón
>>
>> Supongamos que tenemos esta matriz, se quiere conseguir para el mayor
>> valor por fila tomar el valor de la posición que ocupa la primera
>> columna "Var" en base a la columna elegida y si hay varios valores
>> máximos iguales, entonces ejecutar la función "f5" para elegir una y
>> según valor máximo obtenido proceder de la misma manera que antes.
>>
>> El problema es cuando tengo matrices de 3000x3000 o 1x1, y
>> además los dígitos de la columna primera son superiores al puesto en este
>> ejemplo, entonces el tiempo de calculo es excesivo.
>>
>> [image: image.png]
>>
>> codigo:
>>
>
>
>> f5 <- function(x){data1 %>% filter(Clus.Multi.OPTIMO %in%
>> c(EMISOR,RECEPTOR[x])) %>%
>> dplyr::select(1:numvar+1) %>% data.matrix() %>% CohenD()}
>> #
>> #
>> fila = 1
>> rr = nrow(data2)
>> data1 <- data1 %>% mutate(Clus.Multi.OPTIMO=Clus.Multi.MAX)
>> #
>> repeat{
>> smc <-
>> sum(data2[fila,((2+fila):(nrow(data2)+2))]==max(data2[fila,((2+fila):(nrow(data2)+2))]))
>> EMISOR <- data2[fila,1]$Var
>> RECEPTOR <-
>> data2[which(as.vector(t(data2[fila,])[,1])==max(data2[fila,((2+fila):(nrow(data2)+2))]))-2,1]$Var
>> Rmax <- RECEPTOR[mclapply((1:smc),f5) %>% unlist() %>% which.max()]
>> data1$Clus.Multi.OPTIMO[which(data1$Clus.Multi.MAX ==
>> data2[fila,1]$Var)] <- Rmax
>> fila = fila + 1
>> if (fila == rr) {break}
>> }
>>
>
>
>>
>>
>>
>> 
>>  Libre
>> de virus. www.avast.com
>> 
>> <#m_-1660742982892200730_m_-198326376745946536_DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>
>>
>> El dom, 13 dic 2020 a las 12:49, Carlos Ortega ()
>> escribió:
>>
>>> Hola,
>>>
>>> Mejor si pones un ejemplo de tu matriz y cuentas lo que quieres hacer...
>>> El  enfoque puede ser muy diferente al que has planteado.
>>>
>>> Gracias,
>>> Calros Ortega
>>> www.qualityexcellence.es
>>>
>>> El dom, 13 dic 2020 a las 12:33, Carlos Santos (<
>>> carlossantos@gmail.com>) escribió:
>>>
 Buen dia,

 Tengo un problema cuando ejecuto la siguiente rutina, porque con una
 matriz
 muy grande el tiempo de ejecución se va a bastantes  horas.

 Cualquier idea para mejorarlo y reducir significativamente el tiempo,
 estaría muy agradecido

 Muchas gracias por vuestra ayuda


 #_

 f5 <- function(x){data1 %>% filter(Clus.Multi.OPTIMO %in%
 c(EMISOR,RECEPTOR[x])) %>%
 dplyr::select(1:numvar+1) %>% data.matrix() %>% CohenD()}

 #

 __

 fila = 1
 rr = nrow(data2)

 repeat{
 smc <-

 sum(data2[fila,((2+fila):(nrow(data2)+2))]==max(data2[fila,((2+fila):(nrow(data2)+2))]))
 EMISOR <- data2[fila,1]$Var
 RECEPTOR <-

 data2[which(as.vector(t(data2[fila,])[,1])==max(data2[fila,((2+fila):(nrow(data2)+2))]))-2,1]$Var

 Rmax <- RECEPTOR[mclapply((1:smc),f5) %>% unlist() %>% which.max()]

 data1$Clus.Multi.OPTIMO[which(data1$Clus.Multi.MAX ==
  data2[fila,1]$Var)] <- Rmax
 fila = fila + 1
 if (fila == rr) {break}
 }

 <
 https://www.avast.com/sig-email?utm_medium=email_source=link_campaign=sig-email_content=webmail
 >
 Libre
 de virus. www.avast.com
 <
 https://www.avast.com/sig-email?utm_medium=email_source=link_campaign=sig-email_content=webmail
 >
 <#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>

 [[alternative HTML version deleted]]

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

-- 
Saludos,
Carlos Ortega
www.qualityexcellence.es
___
R-help-es mailing list
R-help-es@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-help-es


Re: [R-es] Como puedo reducir el tiempo de ejecución en la siguiente rutina

2020-12-13 Thread Carlos Santos
>
> Perdón Carlos, con las prisas se me olvidó por completo añadir lo que
> faltaba, tienes toda la razón
>
> Supongamos que tenemos esta matriz, se quiere conseguir para el mayor
> valor por fila tomar el valor de la posición que ocupa la primera
> columna "Var" en base a la columna elegida y si hay varios valores
> máximos iguales, entonces ejecutar la función "f5" para elegir una y
> según valor máximo obtenido proceder de la misma manera que antes.
>
> El problema es cuando tengo matrices de 3000x3000 o 1x1, y
> además los dígitos de la columna primera son superiores al puesto en este
> ejemplo, entonces el tiempo de calculo es excesivo.
>
> [image: image.png]
>
> codigo:
>


> f5 <- function(x){data1 %>% filter(Clus.Multi.OPTIMO %in%
> c(EMISOR,RECEPTOR[x])) %>%
> dplyr::select(1:numvar+1) %>% data.matrix() %>% CohenD()}
> #
> #
> fila = 1
> rr = nrow(data2)
> data1 <- data1 %>% mutate(Clus.Multi.OPTIMO=Clus.Multi.MAX)
> #
> repeat{
> smc <-
> sum(data2[fila,((2+fila):(nrow(data2)+2))]==max(data2[fila,((2+fila):(nrow(data2)+2))]))
> EMISOR <- data2[fila,1]$Var
> RECEPTOR <-
> data2[which(as.vector(t(data2[fila,])[,1])==max(data2[fila,((2+fila):(nrow(data2)+2))]))-2,1]$Var
> Rmax <- RECEPTOR[mclapply((1:smc),f5) %>% unlist() %>% which.max()]
> data1$Clus.Multi.OPTIMO[which(data1$Clus.Multi.MAX ==
> data2[fila,1]$Var)] <- Rmax
> fila = fila + 1
> if (fila == rr) {break}
> }
>


>
>
>
> 
>  Libre
> de virus. www.avast.com
> 
> <#m_-198326376745946536_DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>
>
> El dom, 13 dic 2020 a las 12:49, Carlos Ortega ()
> escribió:
>
>> Hola,
>>
>> Mejor si pones un ejemplo de tu matriz y cuentas lo que quieres hacer...
>> El  enfoque puede ser muy diferente al que has planteado.
>>
>> Gracias,
>> Calros Ortega
>> www.qualityexcellence.es
>>
>> El dom, 13 dic 2020 a las 12:33, Carlos Santos (<
>> carlossantos@gmail.com>) escribió:
>>
>>> Buen dia,
>>>
>>> Tengo un problema cuando ejecuto la siguiente rutina, porque con una
>>> matriz
>>> muy grande el tiempo de ejecución se va a bastantes  horas.
>>>
>>> Cualquier idea para mejorarlo y reducir significativamente el tiempo,
>>> estaría muy agradecido
>>>
>>> Muchas gracias por vuestra ayuda
>>>
>>>
>>> #_
>>>
>>> f5 <- function(x){data1 %>% filter(Clus.Multi.OPTIMO %in%
>>> c(EMISOR,RECEPTOR[x])) %>%
>>> dplyr::select(1:numvar+1) %>% data.matrix() %>% CohenD()}
>>>
>>> #
>>>
>>> __
>>>
>>> fila = 1
>>> rr = nrow(data2)
>>>
>>> repeat{
>>> smc <-
>>>
>>> sum(data2[fila,((2+fila):(nrow(data2)+2))]==max(data2[fila,((2+fila):(nrow(data2)+2))]))
>>> EMISOR <- data2[fila,1]$Var
>>> RECEPTOR <-
>>>
>>> data2[which(as.vector(t(data2[fila,])[,1])==max(data2[fila,((2+fila):(nrow(data2)+2))]))-2,1]$Var
>>>
>>> Rmax <- RECEPTOR[mclapply((1:smc),f5) %>% unlist() %>% which.max()]
>>>
>>> data1$Clus.Multi.OPTIMO[which(data1$Clus.Multi.MAX ==
>>>  data2[fila,1]$Var)] <- Rmax
>>> fila = fila + 1
>>> if (fila == rr) {break}
>>> }
>>>
>>> <
>>> https://www.avast.com/sig-email?utm_medium=email_source=link_campaign=sig-email_content=webmail
>>> >
>>> Libre
>>> de virus. www.avast.com
>>> <
>>> https://www.avast.com/sig-email?utm_medium=email_source=link_campaign=sig-email_content=webmail
>>> >
>>> <#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>
>>>
>>> [[alternative HTML version deleted]]
>>>
>>> ___
>>> 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
>>
>
___
R-help-es mailing list
R-help-es@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-help-es


Re: [R-es] Como puedo reducir el tiempo de ejecución en la siguiente rutina

2020-12-13 Thread Carlos Santos
Perdón Carlos, con las prisas se me olvidó por completo añadir lo que
faltaba, tienes toda la razón

Supongamos que tenemos esta matriz, se quiere conseguir para el mayor valor
por fila tomar el valor de la posición que ocupa la primera columna "Var"
en base a la columna elegida y si hay varios valores máximos iguales,
entonces ejecutar la función "f5" para elegir una y según valor máximo
obtenido proceder de la misma manera que antes.

El problema es cuando tengo matrices de 3000x3000 o 1x1, y
además los dígitos de la columna primera son superiores al puesto en este
ejemplo, entonces el tiempo de calculo es excesivo.

[image: image.png]

codigo:



Libre
de virus. www.avast.com

<#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>

El dom, 13 dic 2020 a las 12:49, Carlos Ortega ()
escribió:

> Hola,
>
> Mejor si pones un ejemplo de tu matriz y cuentas lo que quieres hacer...
> El  enfoque puede ser muy diferente al que has planteado.
>
> Gracias,
> Calros Ortega
> www.qualityexcellence.es
>
> El dom, 13 dic 2020 a las 12:33, Carlos Santos (<
> carlossantos@gmail.com>) escribió:
>
>> Buen dia,
>>
>> Tengo un problema cuando ejecuto la siguiente rutina, porque con una
>> matriz
>> muy grande el tiempo de ejecución se va a bastantes  horas.
>>
>> Cualquier idea para mejorarlo y reducir significativamente el tiempo,
>> estaría muy agradecido
>>
>> Muchas gracias por vuestra ayuda
>>
>>
>> #_
>>
>> f5 <- function(x){data1 %>% filter(Clus.Multi.OPTIMO %in%
>> c(EMISOR,RECEPTOR[x])) %>%
>> dplyr::select(1:numvar+1) %>% data.matrix() %>% CohenD()}
>>
>> #
>>
>> __
>>
>> fila = 1
>> rr = nrow(data2)
>>
>> repeat{
>> smc <-
>>
>> sum(data2[fila,((2+fila):(nrow(data2)+2))]==max(data2[fila,((2+fila):(nrow(data2)+2))]))
>> EMISOR <- data2[fila,1]$Var
>> RECEPTOR <-
>>
>> data2[which(as.vector(t(data2[fila,])[,1])==max(data2[fila,((2+fila):(nrow(data2)+2))]))-2,1]$Var
>>
>> Rmax <- RECEPTOR[mclapply((1:smc),f5) %>% unlist() %>% which.max()]
>>
>> data1$Clus.Multi.OPTIMO[which(data1$Clus.Multi.MAX ==
>>  data2[fila,1]$Var)] <- Rmax
>> fila = fila + 1
>> if (fila == rr) {break}
>> }
>>
>> <
>> https://www.avast.com/sig-email?utm_medium=email_source=link_campaign=sig-email_content=webmail
>> >
>> Libre
>> de virus. www.avast.com
>> <
>> https://www.avast.com/sig-email?utm_medium=email_source=link_campaign=sig-email_content=webmail
>> >
>> <#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>
>>
>> [[alternative HTML version deleted]]
>>
>> ___
>> 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
>
___
R-help-es mailing list
R-help-es@r-project.org
https://stat.ethz.ch/mailman/listinfo/r-help-es


Re: [R-es] Como puedo reducir el tiempo de ejecución en la siguiente rutina

2020-12-13 Thread Carlos Ortega
Hola,

Mejor si pones un ejemplo de tu matriz y cuentas lo que quieres hacer...
El  enfoque puede ser muy diferente al que has planteado.

Gracias,
Calros Ortega
www.qualityexcellence.es

El dom, 13 dic 2020 a las 12:33, Carlos Santos ()
escribió:

> Buen dia,
>
> Tengo un problema cuando ejecuto la siguiente rutina, porque con una matriz
> muy grande el tiempo de ejecución se va a bastantes  horas.
>
> Cualquier idea para mejorarlo y reducir significativamente el tiempo,
> estaría muy agradecido
>
> Muchas gracias por vuestra ayuda
>
>
> #_
>
> f5 <- function(x){data1 %>% filter(Clus.Multi.OPTIMO %in%
> c(EMISOR,RECEPTOR[x])) %>%
> dplyr::select(1:numvar+1) %>% data.matrix() %>% CohenD()}
>
> #
>
> __
>
> fila = 1
> rr = nrow(data2)
>
> repeat{
> smc <-
>
> sum(data2[fila,((2+fila):(nrow(data2)+2))]==max(data2[fila,((2+fila):(nrow(data2)+2))]))
> EMISOR <- data2[fila,1]$Var
> RECEPTOR <-
>
> data2[which(as.vector(t(data2[fila,])[,1])==max(data2[fila,((2+fila):(nrow(data2)+2))]))-2,1]$Var
>
> Rmax <- RECEPTOR[mclapply((1:smc),f5) %>% unlist() %>% which.max()]
>
> data1$Clus.Multi.OPTIMO[which(data1$Clus.Multi.MAX ==
>  data2[fila,1]$Var)] <- Rmax
> fila = fila + 1
> if (fila == rr) {break}
> }
>
> <
> https://www.avast.com/sig-email?utm_medium=email_source=link_campaign=sig-email_content=webmail
> >
> Libre
> de virus. www.avast.com
> <
> https://www.avast.com/sig-email?utm_medium=email_source=link_campaign=sig-email_content=webmail
> >
> <#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>
>
> [[alternative HTML version deleted]]
>
> ___
> R-help-es mailing list
> R-help-es@r-project.org
> https://stat.ethz.ch/mailman/listinfo/r-help-es
>


-- 
Saludos,
Carlos Ortega
www.qualityexcellence.es

[[alternative HTML version deleted]]

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


[R-es] Como puedo reducir el tiempo de ejecución en la siguiente rutina

2020-12-13 Thread Carlos Santos
Buen dia,

Tengo un problema cuando ejecuto la siguiente rutina, porque con una matriz
muy grande el tiempo de ejecución se va a bastantes  horas.

Cualquier idea para mejorarlo y reducir significativamente el tiempo,
estaría muy agradecido

Muchas gracias por vuestra ayuda

#_

f5 <- function(x){data1 %>% filter(Clus.Multi.OPTIMO %in%
c(EMISOR,RECEPTOR[x])) %>%
dplyr::select(1:numvar+1) %>% data.matrix() %>% CohenD()}

#
__

fila = 1
rr = nrow(data2)

repeat{
smc <-
sum(data2[fila,((2+fila):(nrow(data2)+2))]==max(data2[fila,((2+fila):(nrow(data2)+2))]))
EMISOR <- data2[fila,1]$Var
RECEPTOR <-
data2[which(as.vector(t(data2[fila,])[,1])==max(data2[fila,((2+fila):(nrow(data2)+2))]))-2,1]$Var

Rmax <- RECEPTOR[mclapply((1:smc),f5) %>% unlist() %>% which.max()]

data1$Clus.Multi.OPTIMO[which(data1$Clus.Multi.MAX ==
 data2[fila,1]$Var)] <- Rmax
fila = fila + 1
if (fila == rr) {break}
}


Libre
de virus. www.avast.com

<#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>

[[alternative HTML version deleted]]

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