Skip to content

Commit

Permalink
rowwise() + across() + c_across()
Browse files Browse the repository at this point in the history
  • Loading branch information
perlatex committed Oct 3, 2022
1 parent 45c3042 commit 93cdbe0
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions tidyverse_beauty_of_across1.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -552,6 +552,9 @@ df %>%
### 案例:替换一行中最大的值

看一行中哪个最大,最大的变为1,其余的变为0
```{r}
df
```

```{r beauty-of-across-25}
replace_rowwise_max <- function(vec) {
Expand Down Expand Up @@ -580,6 +583,15 @@ df %>%
```


最风骚的是

```{r}
df %>%
rowwise() %>%
mutate(
across(x:z, ~ if_else(.x == max(c_across(x:z)), 1, 0))
)
```


## across()总结
Expand Down

0 comments on commit 93cdbe0

Please sign in to comment.