search for: group_by

Displaying 20 results from an estimated 180 matches for "group_by".

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 = gl(3, 10, labels = letters[4:6])) df %>% group_...
2017 Sep 09
0
Avoid duplication in dplyr::summarise
...ion 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 = letters[4:6])) ##To get all summary of your data df%>% gather(X_name,X_value,X1:X4)%>% group_by(f1,f2,X_name)%>% do(describe(.$X_value)) ##To obtain only means of your data df%>% gather(X_name,X_value,X1:X4)%>% group_by(f1,f2,X_name)%>% do(describe(.$X_value))%>% select(mean)%>%# You select only mean value spread(X_name,mean)# Vincent Med venlig hilsen/ Best reg...
2017 Sep 09
1
Avoid duplication in dplyr::summarise
...sage 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 how you set your two factors because the two group_by()'s will give the identical groupings, An alternative which confirms that the function s() does what you want might be: df <- data.frame(matrix(rnorm(40), 10, 4), f1 = base::sample(letters[1:3],30,replace=TRUE), f2 = base::sample(letters[4:6],30,replace=TRU...
2023 Nov 03
2
Sum data according to date in sequence
...gykWh") dput(head(dt1)) > dput(head(dt1))structure(c(16814, 16814, 16814, 16815, 16815, 16815, 4.680496, 6.272414, 1.032782, 11.004884, 10.096824, 6.658797), dim = c(6L, 2L), dimnames = list(NULL, c("date", "EnergykWh"))) Then I tried this: library(dplyr) dt1 %>% group_by(date) %>% summarise(EnergykWh.sum = sum(EnergykWh)) and got this errors dt1 %>%+ group_by(date) %>%+ summarise(EnergykWh.sum = sum(EnergykWh))Error in UseMethod("group_by") : no applicable method for 'group_by' applied to an object of class "c('matrix...
2012 Oct 23
0
multidimensional Array or Hash with group_by 'created_at'
Hello, i want to create a multidimensional Array or Hash with group_by ''created_at''. 3 dimensions needed: myArray[week][day][data] currently i only created it with 2 dimesions: #model def self.group_per_day all.group_by{|t| t.created_at.strftime("%d. %B, %Y")}.sort #"%U" for Weeks end #controller @pdf_activities = Activity.g...
2019 May 20
2
Agrupar por suma y cuenta con dplyr
...información de transferencias monetarias por paciente provincia y modalidad de atención. Necesito hacer en una misma operación una suma de dinero por provincia y modalidad y a su vez una cuenta de pacientes por provincia y modalidad. Esto funciona bien: transferencias<-becas_modalidades %>% group_by(PROVINCIA,Modalidad) %>% summarize(dinero = sum(PRELIQUIDACION))%>% arrange(desc(dinero)) Pero esto no: transferencias<-becas_modalidades %>% group_by(PROVINCIA,Modalidad) %>% summarize(dinero = sum(PRELIQUIDACION),(cuenta=count(IDPACIENTE)))%>% arrange(desc(dinero)) str(...
2023 Nov 03
1
Sum data according to date in sequence
...08874, 1.469384, 2.996239, 0.303222, 4.988339, 8.131804, 0.117156, 3.285669, 1.175608, 3.677487, 1.068393, 8.820755, 8.138583, 9.0575)), row.names = c(NA, 20L), class = "data.frame") # convert date from character to Date byDate <- input |> mutate(newdate = mdy(date)) |> group_by(newdate) |> summarise(total = sum(EnergykWh)) byDate ## # A tibble: 5 ? 2 ## newdate total ## <date> <dbl> ## 1 2016-01-14 12.0 ## 2 2016-01-15 32.6 ## 3 2016-01-16 21.3 ## 4 2016-01-17 22.9 ## 5 2016-01-18 9.06 Thanks Jim Holtman *Data Munger Guru* *What is the...
2018 Mar 22
1
Calculate weighted proportions for several factors at once
...group=paste0('reg', 1:5), var1=rep(c('male','female'), times=45), var2=rep(c('low','med','high'), each=30)) %>% tbl_df() # instead of doing this separately for each factor ... df2 <- df1 %>% group_by(group) %>% dplyr::count(var1, wt=wt) %>% mutate(prop1=n/sum(n)) df3 <- df1 %>% group_by(group) %>% dplyr::count(var2, wt=wt) %>% mutate(prop2=n/sum(n)) %>% left_join(df2, by='group') # I would like to do something like the following (which does of course n...
2018 Feb 10
2
Optimizar función
...rte <- c(3,6,3,6,9,6,9,7,9,7,4,8,2,8) datos<-data.frame(distrito=distrito,Sex=Sex,Edad=Edad,Ingreso=Ingreso,Aporte=Aporte) Quiero aplicar la function *summarise *del paquete *dplyr *a las 3 variables númericas. Para la variable Aporte por ejemplo: descrip<-function(data) { grupos <- group_by(data, distrito) result <- summarise(grupos, media = mean(Aporte), maximo = max(Aporte), minimo = min(Aporte), desvio= sd(Aporte) ) return(result) } Pero me gustaría automatizarla para que corra para todas las variables del...
2006 May 03
2
grouped output
hello, Suppose I have a table that looks like this: center name email Health Jon jon@test.com Health Bob bob@test.com Admin Jane jan@test.com Admin Jill jill@test.com I would like the output to look like this: Health Jon jon@test.com Bob bob@test.com Admin Jane jan@test.com Jill jill@test.com when i using cold fusion, this was easy via a tag called cfoutput. when i was using java, this was
2008 Mar 12
3
Some random rails, and maybe Ruby, questions..
Hi, I''m attempting to create a users statistics controller, and have saved up some questions regarding this for this post. So, please comment on any one of them, if not all :-) 1) Is there a library somewhere for doing stats? (e.g. mean, median, sd, skewness..) on an array in rails? 2) What library would you recommend for "publication ready" (i.e. not cheesy) histograms,
2019 Oct 05
5
should base R have a piping operator ?
...ncerning your examples: * I love fread but I think it makes a lot of subjective choices that are best associated with a package. I think it changed a lot with time and can still change, and we have great developers willing to maintain it and be reactive regarding feature requests or bug reports *.group_by() adds a class that works only (or mostly) with tidyverse verbs, that's very easy to dismiss it as an inclusion in base R. * summarize is an alternative to aggregate, that would be very confusing to have both Now to be fair to your argument we could think of other functions such as data.table...
2020 Sep 13
3
CALCULAR SALDO DE CUENTA CORRIENTE
...893. 42096. 8 256 2020-01-13 40100006 30-65527599-8 20-A-363538 0 2646. 39450. 9 256 2020-01-13 40100006 30-65527599-8 20-A-363538 0 1985. 37465. *SENTENCIA QUE ESTOY UTILIZANDO:* #ORDENAR FILAS POR FECHA Y CALCULAR SALDO Diario_Serie5 <- Diario_Serie5 %>% group_by(FECHA) %>% mutate(SALDO = cumsum(ARS_DEB)-cumsum(ARS_HAB)) Me está calculando bien la primera fila, pero luego a partir de la segunda, no está funcionando bien. Agradezco mucho la ayuda que me puedan dar. Jesús _________________ *Jesús MARTÍN FRADE * Skype: jmfpas T...
2009 Mar 04
10
total per user
...for example: User 1: Jan $3000 Feb $4000 March $1500, etc. I can get this to work if I sum totals (aggregate of all users) but just not by user. Here is my code in the controller: def index @users = User.find :all, :order => ''name ASC'' @deal_groups = Deal.find(:all).group_by {|t| t.saledate.at_beginning_of_month} end And then the code in the View <% for user in @users %> <ul id="monthly-revs"> <strong><li><%=h Time.now.year %></li></strong> <% user.deal_groups.keys.sort.each do |month| %> <li>&lt...
2013 Jan 24
12
group by + sum
Hi.. I need some support... table: week_id, user_id, project_id, hours ex. => 33, 2, 1, 10 34, 2,1,15 33, 2, 2, 20 35, 3, 1,20 etc. Want to display a sum of hours per week_id per user_id I have: @hours = HourUser.includes(:user).group_by { |h| h.week_id } @hours.keys.sort.each do |hour| @hours[hour].collect(&:stunden).sum Hours are summed up, but not sorted by user_id.. How to get that? Thanks Werner -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To...
2023 Nov 02
4
Sum data according to date in sequence
...16 3.677487 17 PALO ALTO CA / CAMBRIDGE #1 1/17/2016 13:53 1.068393 18 PALO ALTO CA / CAMBRIDGE #1 1/17/2016 19:03 8.820755 19 PALO ALTO CA / CAMBRIDGE #1 1/17/2016 22:00 8.138583 20 PALO ALTO CA / CAMBRIDGE #1 1/18/2016 8:58 9.057500 I have tried this: library(dplyr) sums <- dt1 %>% group_by(date) %>% summarise(EnergykWh = sum(EnergykWh)) head(sums,20) The date is not by daily sequence but by year sequence. > head(sums,20)# A tibble: 20 ? 2 date EnergykWh <chr> <dbl> 1 1/1/2017 25.3 2 1/1/2018 61.0 3 1/1/2019 0.627 4 1/1/2020...
2006 Apr 09
6
Write/Display AR query as Grouped Results?
I''ve got a publications table that contains an author_id foreign key and a pubrole_id foreign key. What I want to do is query the DB using AR so that I can get a list of all publications that belong_to a particular author, and group the results by the pubrole.role_name (Author, Joint Author, Editor, etc.) so that the results look something like: Author book1 info book2 info etc.
2019 Feb 16
4
Duda error sintaxis
...ted with `aes() or `aes_()`. Alguien me puede orientar sobre que estoy haciendo mal, llevo mucho rato atascada. Muchas gracias df_nuevofinal %>% filter( District == "University" | District == "Boyer" | District == "Parc" | District == "Berri1") %>% group_by(week_day) %>% ggplot(df_nuevofinal,aes (x=week_day, y=District)) + geom_col() [[alternative HTML version deleted]]
2016 May 12
2
Division entre el numero de ocurrencias parciales y totales dentro de un DataFrame de manera eficiente
...LSE) Y necesito contar los casos donde aparece "a" y "x" y dividirlo por el total de filas con primera columna=a. , df1: > df1 a b 1 a x 2 b y 3 c z 4 b w 5 c x 6 a y 7 b z 8 c w 9 b x 10 c y 11 a z 12 b w 13 c x 14 b y 15 c z 16 b w Si hago df2<-df1%>%group_by(a)%>%count(a,b,c) df3<-df1%>%group_by(a)%>%count(a) en el df2: a b n (chr) (chr) (int) 1 a x 1 2 a y 1 3 a z 1 4 b w 3 5 b x 1 6 b y 2 7 b z 1 8 c w 1 9 c...
2019 Jul 27
3
[PATCH libnbd] lib: Use symbol versions.
This patch adds support for symbol versions. It is based on what libvirt does. The generated syms file looks like: LIBNBD_1.0 { global: nbd_...; nbd_...; local: *; }; In a future stable 1.2 release, new symbols would go into a new section which would look like this: LIBNBD_1.2 { global: nbd_new_symbol; nbd_another_new_symbol; local: *; } LIBNBD_1.0; In my testing the