You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am attempting to perform a rowwise mean calculation across multiple columns. The function below works fine
df <- tibble(x = runif(6), y = runif(6), z = runif(6))
df %>% rowwise() %>% mutate(m = mean(c(x, y, z)))
However, when I use a colon to specify the columns to perform the mean function R will return the outputs from the first column.
df %>% rowwise() %>% mutate(m = mean(c(x:z)))
Below is the reprex for the issue
library(tidyverse)
#> Warning: package 'tidyverse' was built under R version 4.4.1#> Warning: package 'ggplot2' was built under R version 4.4.1#> Warning: package 'tibble' was built under R version 4.4.1#> Warning: package 'tidyr' was built under R version 4.4.1#> Warning: package 'readr' was built under R version 4.4.1#> Warning: package 'purrr' was built under R version 4.4.1#> Warning: package 'dplyr' was built under R version 4.4.1#> Warning: package 'stringr' was built under R version 4.4.1#> Warning: package 'forcats' was built under R version 4.4.1#> Warning: package 'lubridate' was built under R version 4.4.1
set.seed(111)
df<- tibble(x= runif(6), y= runif(6), z= runif(6))
df %>% rowwise() %>% mutate(m= mean(c(x, y, z)))
#> # A tibble: 6 × 4#> # Rowwise: #> x y z m#> <dbl> <dbl> <dbl> <dbl>#> 1 0.593 0.0107 0.0671 0.224#> 2 0.726 0.532 0.0475 0.435#> 3 0.370 0.432 0.156 0.320#> 4 0.515 0.0937 0.446 0.352#> 5 0.378 0.556 0.171 0.368#> 6 0.418 0.590 0.967 0.658df %>% rowwise() %>% mutate(m= mean(c(x:z)))
#> # A tibble: 6 × 4#> # Rowwise: #> x y z m#> <dbl> <dbl> <dbl> <dbl>#> 1 0.593 0.0107 0.0671 0.593#> 2 0.726 0.532 0.0475 0.726#> 3 0.370 0.432 0.156 0.370#> 4 0.515 0.0937 0.446 0.515#> 5 0.378 0.556 0.171 0.378#> 6 0.418 0.590 0.967 0.418
I am attempting to perform a rowwise mean calculation across multiple columns. The function below works fine
However, when I use a colon to specify the columns to perform the mean function R will return the outputs from the first column.
Below is the reprex for the issue
Created on 2024-10-10 with reprex v2.1.1
Standard output and standard error
Session info
The text was updated successfully, but these errors were encountered: