You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@arrow.apache.org by "eitsupi (via GitHub)" <gi...@apache.org> on 2023/05/22 14:47:22 UTC

[GitHub] [arrow] eitsupi commented on a diff in pull request #35702: [R][Documentation] Document workaround for window-like functionality

eitsupi commented on code in PR #35702:
URL: https://github.com/apache/arrow/pull/35702#discussion_r1200622342


##########
r/vignettes/data_wrangling.Rmd:
##########
@@ -165,6 +165,34 @@ sw2 %>%
   transmute(name, height, mass, res = residuals(lm(mass ~ height)))
 ```
 
+Because window functions are not supported, computing an aggregation like `mean()` on a grouped table or within a rowwise opertation like `filter()`  is not supported:
+
+```{r}
+sw %>%
+  select(1:4) %>%
+  filter(!is.na(hair_color)) %>%
+  group_by(hair_color) %>%
+  filter(height < mean(height, na.rm = TRUE))
+```
+
+This operation can be accomplished in arrow by computing the aggregation separately, for example within a join operation: 
+
+```{r}
+
+sw %>%  
+  select(1:4) %>%
+  filter(!is.na(hair_color)) %>%
+  left_join(sw %>% 
+    group_by(hair_color) %>%
+    summarize(mean_height = mean(height, na.rm = TRUE)) 
+    ) %>%
+  filter(height < mean_height) %>% 
+  select(-mean_height) %>%
+  collect()
+

Review Comment:
   How about formatting it as follows?
   
   ```suggestion
   sw %>%
     select(1:4) %>%
     filter(!is.na(hair_color)) %>%
     left_join(
       sw %>% 
         group_by(hair_color) %>%
         summarize(mean_height = mean(height, na.rm = TRUE)) 
       ) %>%
     filter(height < mean_height) %>% 
     select(!mean_height) %>%
     collect()
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@arrow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org