search for: group_by

Displaying 20 results from an estimated 196 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...
2024 May 24
1
dplyr, group_by and selective action according to each group
Dear RHelp-list, ?? Using dplyr and the group_by approach on a dataframe, I want to be able to apply a specific action according to the group name. The code bellow works, but I am not able to write it in a more esthetic way using dplyr. Can somebody help me to find a better solution ? Thank you Best regards Laurent df_test <- data.frame...
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(...
2024 May 24
1
dplyr, group_by and selective action according to each group
...ose and call the function you want. You may disagree, of course. Caveat: I make no claims about the efficiency or lack thereof of the above. Cheers, Bert On Fri, May 24, 2024 at 12:35?PM Laurent Rhelp <laurentRHelp at free.fr> wrote: > Dear RHelp-list, > > Using dplyr and the group_by approach on a dataframe, I want to be > able to apply a specific action according to the group name. The code > bellow works, but I am not able to write it in a more esthetic way using > dplyr. Can somebody help me to find a better solution ? > > Thank you > > Best regards >...
2024 May 25
1
dplyr, group_by and selective action according to each group
...if you are interested in doing things groupwise across all groups such as getting a count of how many are in each group or some vectorized operation like getting the mean or SD of a column or whatever. But for the purposes mentioned here, consider a lower-tech alternative such as this. Instead of group_by(gr) which is a trivial group, consider using other dplyr predicates like "mutate" to trigger on all rows that meet a condition like gr having a value of 3 as in: mutate(DATAFRAME, result=ifelse(gr==3, f(), whatever) The above is not a full-blown example but something similar can be tail...
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...
2024 Sep 17
1
(no subject)
..., 7, > > 5, > > > 8, 5, 1, 2, 4, 7, 6, 6))) > > > colnames(test) <-c("cp1","cp2","role","groupid") > > > > > > What I have done so far is the following, that works: > > > test %>% > > > group_by(groupid) %>% > > > mutate(across(starts_with("cp"), list(mean = mean))) > > > > > > But the problem is with NA: everytime the mean encounters a NA, it > > creates > > > NA for all group members. > > > I need the software to calculat...