[R] Fastest way to extract rows of smaller matrix many times by index to make larger matrix? and multiply columsn of matrix by vector

2021-09-13 Thread nevil amos
Hi is there a faster way to "extract" rows of a matrix many times to for a longer matrix based in a vector or for indices than M[ V, ] I need to "expand" ( rather than subset) a matrix M of 10-100,000 rows x ~50 columns to produce a matrix with a greater number (10^6-10^8) of rows using a vector

Re: [R] tidyverse: grouped summaries (with summarize) [RESOLVED]

2021-09-13 Thread Rich Shepard
On Mon, 13 Sep 2021, Bert Gunter wrote: If you are interested in extracting seasonal patterns from time series, you might wish to check out ?stl (in the stats package). Of course, there are all sorts of ways in many packages to fit seasonality in time series that are more sophisticated, but prob

Re: [R] tidyverse: grouped summaries (with summarize) [RESOLVED]

2021-09-13 Thread Bert Gunter
If you are interested in extracting seasonal patterns from time series, you might wish to check out ?stl (in the stats package). Of course, there are all sorts of ways in many packages to fit seasonality in time series that are more sophisticated, but probably also more complicated, than your manua

Re: [R] tidyverse: grouped summaries (with summarize) [RESOLVED]

2021-09-13 Thread Rich Shepard
On Mon, 13 Sep 2021, Avi Gross via R-help wrote: Just FYI, Rich, the way the idiom with pipeline works does allow but not require the method you used: ... But equally valid are forms that assign the result at the end: Avi, I'll read more about tidyverse and summarize() in R and not just i

Re: [R] tidyverse: grouped summaries (with summarize) [RESOLVED]

2021-09-13 Thread Avi Gross via R-help
Just FYI, Rich, the way the idiom with pipeline works does allow but not require the method you used: Yours was RESULT <- DATAFRAME %>% FN1(args) %>% ... FNn(args) But equally valid are forms that assign the result at the end: DATAFRAME %>% FN1(args) %>% ...

Re: [R] tidyverse: grouped summaries (with summarize) [RESOLVED]

2021-09-13 Thread Rich Shepard
On Mon, 13 Sep 2021, Avi Gross via R-help wrote: As Eric has pointed out, perhaps Rich is not thinking pipelined. Summarize() takes a first argument as: summarise(.data=whatever, ...) But in a pipeline, you OMIT the first argument and let the pipeline supply an argument silently. Av

Re: [R] Error msg trying to load R Commander with an older R edition...

2021-09-13 Thread John Fox
Dear Brian, On 2021-09-13 9:33 a.m., Brian Lunergan wrote: Hi folks: I'm running Linux Mint 19.3 on my machine. Tried to install a more recent edition of R but I couldn't seem to get it working so I pulled it off and went with a good, basic install of the edition available through the software

Re: [R] tidyverse: grouped summaries (with summArize)

2021-09-13 Thread Avi Gross via R-help
I think we wandered away into a package rather than base R, but the request seems easy enough. Just FYI, Rich, as you seem not to have incorporated the advice we gave yet about the first argument, your use of group_by() is a tad odd. disc %>% group_by(hour) %>% group_by(day) %>%

Re: [R] tidyverse: grouped summaries (with summerize)

2021-09-13 Thread Avi Gross via R-help
As Eric has pointed out, perhaps Rich is not thinking pipelined. Summarize() takes a first argument as: summarise(.data=whatever, ...) But in a pipeline, you OMIT the first argument and let the pipeline supply an argument silently. What I think summarize saw was something like: summari

Re: [R] tidyverse: grouped summaries (with summerize)

2021-09-13 Thread Rich Shepard
On Tue, 14 Sep 2021, Eric Berger wrote: This code is not correct: disc_by_month %>% group_by(year, month) %>% summarize(disc_by_month, vol = mean(cfs, na.rm = TRUE)) It should be: disc %>% group_by(year,month) %>% summarize(vol=mean(cfs,na.rm=TRUE) Eric/Avi: That makes no difference:

Re: [R] tidyverse: grouped summaries (with summerize)

2021-09-13 Thread Eric Berger
This code is not correct: disc_by_month %>% group_by(year, month) %>% summarize(disc_by_month, vol = mean(cfs, na.rm = TRUE)) It should be: disc %>% group_by(year,month) %>% summarize(vol=mean(cfs,na.rm=TRUE) On Tue, Sep 14, 2021 at 12:51 AM Rich Shepard wrote: > On Mon, 13 Sep 2

Re: [R] tidyverse: grouped summaries (with summerize)

2021-09-13 Thread Rich Shepard
On Mon, 13 Sep 2021, Rich Shepard wrote: That's what I thought I did. I'll rewrite the script and work toward the output I need. Still not the correct syntax. Command is now: disc_by_month %>% group_by(year, month) %>% summarize(disc_by_month, vol = mean(cfs, na.rm = TRUE)) and result

Re: [R] tidyverse: grouped summaries (with summerize)

2021-09-13 Thread Rich Shepard
On Mon, 13 Sep 2021, Avi Gross via R-help wrote: Did I miss something? Avi, Probably not. The summarise() command is telling you that you had not implicitly grouped the data and it made a guess. The canonical way is: ... %>% group_by(year, month, day, hour) %>% summarise(...) After sendi

Re: [R] tidyverse: grouped summaries (with summerize)

2021-09-13 Thread Avi Gross via R-help
Rich, Did I miss something? The summarise() command is telling you that you had not implicitly grouped the data and it made a guess. The canonical way is: ... %>% group_by(year, month, day, hour) %>% summarise(...) You decide which fields to group by, sometimes including others so they are in

[R] tidyverse: grouped summaries (with summerize)

2021-09-13 Thread Rich Shepard
I changed the data files so the date-times are in five separate columns: year, month, day, hour, and minute; for example, year,month,day,hour,min,cfs 2016,03,03,12,00,149000 2016,03,03,12,10,15 2016,03,03,12,20,151000 2016,03,03,12,30,156000 2016,03,03,12,40,154000 2016,03,03,12,50,15 2016

Re: [R] Evaluating lazily 'f<-' ?

2021-09-13 Thread Leonard Mada via R-help
On 9/13/2021 11:28 PM, Andrew Simmons wrote: > In the example you gave : r(x) <- 1 > r(x) is never evaluated, the above calls `r<-`, > in fact r does not even have to be an existing function. I meant: '*tmp*' <- x; # "x" is evaluated here; 'r<-' is called after this step, which makes sense in

Re: [R] Evaluating lazily 'f<-' ?

2021-09-13 Thread Andrew Simmons
In the example you gave : r(x) <- 1 r(x) is never evaluated, the above calls `r<-`, in fact r does not even have to be an existing function. On Mon, Sep 13, 2021, 16:18 Leonard Mada wrote: > Hello, > > > I have found the evaluation: it is described in the section on subsetting. > The forced eval

Re: [R] Evaluating lazily 'f<-' ?

2021-09-13 Thread Leonard Mada via R-help
Hello, I have found the evaluation: it is described in the section on subsetting. The forced evaluation makes sense for subsetting. On 9/13/2021 9:42 PM, Leonard Mada wrote: > > Hello Andrew, > > > I try now to understand the evaluation of the expression: > > e = expression(r(x) <- 1) > > # pa

Re: [R] Error msg trying to load R Commander with an older R edition...

2021-09-13 Thread Duncan Murdoch
On 13/09/2021 9:33 a.m., Brian Lunergan wrote: Hi folks: I'm running Linux Mint 19.3 on my machine. Tried to install a more recent edition of R but I couldn't seem to get it working so I pulled it off and went with a good, basic install of the edition available through the software manager. So..

Re: [R] Evaluating lazily 'f<-' ?

2021-09-13 Thread Bert Gunter
e = expression(r(x) <- 1) lapply(e, as.list) [[1]] [[1]][[1]] `<-` [[1]][[2]] r(x) [[1]][[3]] [1] 1 ### lapply(e[[1]], as.list) [[1]] [[1]][[1]] `<-` [[2]] [[2]][[1]] r [[2]][[2]] x [[3]] [[3]][[1]] [1] 1 However, I would urge you not to go down this rabbit hole unless

Re: [R] ggsave() with width only

2021-09-13 Thread Adam Wysokiński via R-help
Hi, Instead of ggsave(), use save_plot() from the "cowplot" package: library(ggplot2) library(cowplot) x <- 1:10 y <- x^2 df <- data.frame(x, y) p <- ggplot(df, aes(x, y)) + geom_point() save_plot("/tmp/plot.png", p, base_aspect_ratio = 1, base_width = 5, base_height = NULL) -- Regards, Adam W

[R] Error msg trying to load R Commander with an older R edition...

2021-09-13 Thread Brian Lunergan
Hi folks: I'm running Linux Mint 19.3 on my machine. Tried to install a more recent edition of R but I couldn't seem to get it working so I pulled it off and went with a good, basic install of the edition available through the software manager. So... I'm running version 3.4.4. Mucking about with

[R] dbWriteTable does not append rows in database

2021-09-13 Thread Kai Yang via R-help
Hi List, I want to append some rows from R into sql server. So, I submitted the code below. there is not any error message: dbWriteTable(conn = con, name = "PMDB._Alias_A", value = try1, overwrite=FALSE, append=TRUE, row.names = FALSE) But when I try to query the data from the Sql server, I can n

Re: [R] Evaluating lazily 'f<-' ?

2021-09-13 Thread Leonard Mada via R-help
Hello Andrew, I try now to understand the evaluation of the expression: e = expression(r(x) <- 1) # parameter named "value" seems to be required; 'r<-' = function(x, value) {print("R");} eval(e, list(x=2)) # [1] "R" # both versions work 'r<-' = function(value, x) {print("R");} eval(e, list(x=2

Re: [R] Evaluating lazily 'f<-' ?

2021-09-13 Thread Andrew Simmons
R's parser doesn't work the way you're expecting it to. When doing an assignment like: padding(right(df)) <- 1 it is broken into small stages. The guide "R Language Definition" claims that the above would be equivalent to: `<-`(df, `padding<-`(df, value = `right<-`(padding(df), value = 1)))

Re: [R] Evaluating lazily 'f<-' ?

2021-09-13 Thread Leonard Mada via R-help
Hello Andrew, this could work. I will think about it. But I was thinking more generically. Suppose we have a series of functions: padding(), border(), some_other_style(); Each of these functions has the parameter "right" (or the group of parameters c("right", ...)). Then I could design a fun

Re: [R] Evaluating lazily 'f<-' ?

2021-09-13 Thread Andrew Simmons
I think you're trying to do something like: `padding<-` <- function (x, which, value) { which <- match.arg(which, c("bottom", "left", "top", "right"), several.ok = TRUE) # code to pad to each side here } Then you could use it like df <- data.frame(x=1:5, y = sample(1:5, 5)) padding(df, "

Re: [R] Evaluating lazily 'f<-' ?

2021-09-13 Thread Leonard Mada via R-help
I try to clarify the code: ### right = function(x, val) {print("Right");}; padding = function(x, right, left, top, bottom) {print("Padding");}; 'padding<-' = function(x, ...) {print("Padding = ");}; df = data.frame(x=1:5, y = sample(1:5, 5)); # anything ### Does NOT work as expected 'right<-' =

Re: [R] Evaluating lazily 'f<-' ?

2021-09-13 Thread Duncan Murdoch
On 13/09/2021 9:38 a.m., Leonard Mada wrote: Hello, I can include code for "padding<-"as well, but the error is before that, namely in 'right<-': right = function(x, val) {print("Right");}; # more options: padding = function(x, right, left, top, bottom) {print("Padding");}; 'padding<-' = funct

Re: [R] Evaluating lazily 'f<-' ?

2021-09-13 Thread Leonard Mada via R-help
Hello, I can include code for "padding<-"as well, but the error is before that, namely in 'right<-': right = function(x, val) {print("Right");}; # more options: padding = function(x, right, left, top, bottom) {print("Padding");}; 'padding<-' = function(x, ...) {print("Padding = ");}; df = dat

Re: [R] Evaluating lazily 'f<-' ?

2021-09-13 Thread Duncan Murdoch
On 12/09/2021 10:33 a.m., Leonard Mada via R-help wrote: How can I avoid evaluation? right = function(x, val) {print("Right");}; padding = function(x) {print("Padding");}; df = data.frame(x=1:5, y = sample(1:5, 5)); ### OK '%=%' = function(x, val) {     x = substitute(x); } right(padding(df))

[R] Evaluating lazily 'f<-' ?

2021-09-13 Thread Leonard Mada via R-help
How can I avoid evaluation? right = function(x, val) {print("Right");}; padding = function(x) {print("Padding");}; df = data.frame(x=1:5, y = sample(1:5, 5)); ### OK '%=%' = function(x, val) {     x = substitute(x); } right(padding(df)) %=% 1; # but ugly ### Does NOT work 'right<-' = function(x