Displaying 20 results from an estimated 8000 matches similar to: "quote()/eval() question"
2017 Sep 09
2
Avoid duplication in dplyr::summarise
Dear group,
Is there a way I could avoid the sort of duplication illustrated below?
i.e., I have the same dplyr::summarise function on different group_by
arguments. So I'd like to create a single summarise function that could be
applied to both. My attempt below fails.
df <- data.frame(matrix(rnorm(40), 10, 4),
f1 = gl(3, 10, labels = letters[1:3]),
f2 =
2017 Sep 09
1
Avoid duplication in dplyr::summarise
Hi Lars,
Two comments:
1. You can achieve what you want with a slight modification of your
definition of s(), using the hint from the error message that you need an
argument '.':
s <- function(.) {
dplyr::summarise(., x1m = mean(X1),
x2m = mean(X2),
x3m = mean(X3),
x4m = mean(X4))
}
2. You have not given a great test case in
2017 Sep 09
0
Avoid duplication in dplyr::summarise
Hi Lars
I am not very sure what you really want. However, I am suggesting the
following code that enables (1) to obtain the full summary of your data and
(2) retrieve only mean of X values as function of factors f1 and f2.
library(tidyverse)
library(psych)
df <- data.frame(matrix(rnorm(40), 10, 4),
f1 = gl(3, 10, labels = letters[1:3]),
f2 = gl(3, 10, labels
2018 Feb 10
2
Optimizar función
Buenas para tod en s, tengo una consulta para poder optimizar tiempos. Ejemplo
tengo el siguiente dataframe:
distrito<-c("A","A","A","B","B","B","C","C","C","A","A","B","B","C")
2020 Oct 01
0
summarize_all Function
Hello,
Any of the two will do, the first is now preferred.
library(dplyr)
mtcars %>%
summarise(across(everything(), sum))
mtcars %>%
summarise_all(sum) # no need for `funs()`
Hope this helps,
Rui Barradas
?s 18:29 de 01/10/20, Jeff Reichman escreveu:
> r-help Forum
>
>
>
> I'm using the dplyr:: summarize_all(funs(sum)) function and am receiving a
>
2023 Nov 03
2
Sum data according to date in sequence
Hi,
I tried this:
# extract date from the time stamp
dt1 <- cbind(as.Date(dt$EndDate, format="%m/%d/%Y"), dt$EnergykWh)
head(dt1)
colnames(dt1) <- c("date", "EnergykWh")
and
my dt1 becomes these, the dates are replace by numbers.
dt1 <- cbind(as.Date(dt$EndDate, format="%m/%d/%Y"), dt$EnergykWh)
dput(head(dt1))
colnames(dt1) <-
2017 Nov 09
1
weighted average grouped by variables
Dear Massimo,
It seems straightforward to use weighted.mean() in a dplyr context
library(dplyr)
mydf %>%
group_by(date_time, type) %>%
summarise(vel = weighted.mean(speed, n_vehicles))
Best regards,
ir. Thierry Onkelinx
Statisticus / Statistician
Vlaamse Overheid / Government of Flanders
INSTITUUT VOOR NATUUR- EN BOSONDERZOEK / RESEARCH INSTITUTE FOR NATURE AND
FOREST
Team
2018 Jan 15
0
barplot that displays sums of values of 2 y colums grouped by different variables
It is not generally advisable to get too fancy with stat functions in
ggplot... things can easily get more complicated than ggplot is ready to
handle when it comes to calculations. It is better to create data that
corresponds directly to the graphical representations you are mapping
them to.
Read [1] for more on this philosophy.
[1] H. Wickham, Tidy Data, Journal of Statistical Software,
2023 Nov 03
1
Sum data according to date in sequence
Is this what you are after?
library(tidyverse)
library(lubridate)
input <- structure(list(StationName = c("PALO ALTO CA / CAMBRIDGE #1",
"PALO ALTO CA / CAMBRIDGE #1", "PALO ALTO CA / CAMBRIDGE #1",
"PALO ALTO CA / CAMBRIDGE #1", "PALO ALTO CA / CAMBRIDGE #1",
"PALO ALTO CA / CAMBRIDGE #1", "PALO ALTO CA / CAMBRIDGE
2014 Jan 18
6
My first package
Hi All,
I'm planning to submit my first package to R, and although I read all the
documentation, I'm not very clear on the following 2 items, from which I'd
appreciate your guidance:
1)I understand it is suggested to use the R dev version to build the
package. Which one specifically should I use to build a package on a Mac
OS? How about package dependencies, which version should I
2023 Nov 04
2
Sum data according to date in sequence
?s 01:49 de 03/11/2023, roslinazairimah zakaria escreveu:
> Hi all,
>
> This is the data:
>
>> dput(head(dt1,20))structure(list(StationName = c("PALO ALTO CA / CAMBRIDGE #1",
> "PALO ALTO CA / CAMBRIDGE #1", "PALO ALTO CA / CAMBRIDGE #1",
> "PALO ALTO CA / CAMBRIDGE #1", "PALO ALTO CA / CAMBRIDGE #1",
> "PALO ALTO
2024 Sep 17
1
(no subject)
Hmmm... typos and thinkos ?
Maybe:
mean_narm<- function(x) {
m <- mean(x, na.rm = T)
if (is.nan (m)) NA else m
}
-- Bert
On Mon, Sep 16, 2024 at 4:40?PM CALUM POLWART <polc1410 at gmail.com> wrote:
>
> Rui's solution is good.
>
> Bert's suggestion is also good!
>
> For Berts suggestion you'd make the list bit
>
> list(mean = mean_narm)
>
2016 Apr 01
3
TensorFlow in R
Hi All,
I didn't have much success through my Google search in finding any active
R-related projects to create a wrapper around TensorFlow in R. Anyone know
if this is on the go?
Thanks,
Axel.
[[alternative HTML version deleted]]
2016 Apr 01
3
TensorFlow in R
Hi All,
I didn't have much success through my Google search in finding any active
R-related projects to create a wrapper around TensorFlow in R. Anyone know
if this is on the go?
Thanks,
Axel.
[[alternative HTML version deleted]]
2011 Feb 26
2
Reproducibility issue in gbm (32 vs 64 bit)
Dear List,
The gbm package on Win 7 produces different results for the
relative importance of input variables in R 32-bit relative to R 64-bit. Any
idea why? Any idea which one is correct?
Based on this example, it looks like the relative importance of 2 perfectly
correlated predictors is "diluted" by half in 32-bit, whereas in 64-bit, one
of these predictors gets all the importance
2013 Feb 10
3
Constrained Optimization in R (alabama)
Dear List,
I'm trying to solve this simple optimization problem in R. The parameters
are the exponents to the matrix mm. The constraints specify that each row
of the parameter matrix should sum to 1 and their product to 0. I don't
understand why the constraints are not satisfied at the solution. I must be
misinterpreting how to specify the constrains somehow.
library(alabama)
ff <-
2023 Nov 02
4
Sum data according to date in sequence
Dear all,
I have this set of data. I would like to sum the EnergykWh according date
sequences.
> head(dt1,20) StationName date time EnergykWh
1 PALO ALTO CA / CAMBRIDGE #1 1/14/2016 12:09 4.680496
2 PALO ALTO CA / CAMBRIDGE #1 1/14/2016 19:50 6.272414
3 PALO ALTO CA / CAMBRIDGE #1 1/14/2016 20:22 1.032782
4 PALO ALTO CA / CAMBRIDGE #1 1/15/2016 8:25 11.004884
5
2024 Aug 16
2
boxplot notch
Thanks Ben,
Here the reproducible example.
It works without notch=TRUE, but provides an error with notch=TURE
Error in `geom_boxplot()`:
! Problem while converting geom to grob.
? Error occurred in the 1st layer.
Caused by error in `ans[ypos] <- rep(yes, length.out = len)[ypos]`:
! replacement has length zero
Run `rlang::last_trace()` to see where the error occurred.
Warning message:
In
2017 Nov 09
0
weighted average grouped by variables
Hello
an update about my question: I worked out the following solution (with the package "dplyr")
library(dplyr)
mydf%>%
mutate(speed_vehicles=n_vehicles*mydf$speed) %>%
group_by(date_time,type) %>%
summarise(
sum_n_times_speed=sum(speed_vehicles),
n_vehicles=sum(n_vehicles),
vel=sum(speed_vehicles)/sum(n_vehicles)
)
In fact I was hoping to manage everything in a
2010 Feb 21
4
R on 64-Bit…
Dear R users,
I know this issue came up in the list several times. I’m currently running
R on 32-bit on Windows and due to memory limitation problems would like to
move to a 64-bit environment. I’m exploring my options and would appreciate
your expertise:
1) Windows 64-bit: Prof. Brian Ripley recently posted the experimental
built of R for win 64-bit. I’ll appreciate any feedback on