The following will convert all non-zero numeric values to 1:
df.richness %>% mutate_if(is.numeric, ~1 * (. != 0))
while
df.richness %>% mutate_if(is.numeric, ~1 * (. > 0))
will do that with those greater than zero.
More Related Contents:
- Filling missing dates in a grouped time series – a tidyverse-way?
- combine two data frames with all posible combinations
- Spread with duplicate identifiers (using tidyverse and %>%) [duplicate]
- Canonical tidyverse method to update some values of a vector from a look-up table
- Error with select function from dplyr
- Mutate multiple variable to create multiple new variables
- mutate with case_when and contains
- Add row in each group using dplyr and add_row()
- tidyverse – prefered way to turn a named vector into a data.frame/tibble
- Why does summarize or mutate not work with group_by when I load `plyr` after `dplyr`?
- How to create a lag variable within each group?
- Why are my dplyr group_by & summarize not working properly? (name-collision with plyr)
- Filter data frame by character column name (in dplyr)
- How to number/label data-table by group-number from group_by?
- Remove duplicated rows using dplyr
- dplyr summarise: Equivalent of “.drop=FALSE” to keep groups with zero length in output
- dplyr: “Error in n(): function should not be called directly”
- dplyr: inner_join with a partial string match
- Can dplyr summarise over several variables without listing each one? [duplicate]
- Change value of variable with dplyr
- sample rows of subgroups from dataframe with dplyr
- Assigning Dates to Fiscal Year
- filter function in dplyr errors: object ‘name’ not found
- How to pass dynamic column names in dplyr into custom function?
- R – Group by variable and then assign a unique ID [duplicate]
- R sum a variable by two groups [duplicate]
- data.table row-wise sum, mean, min, max like dplyr?
- Run a custom function on a data frame in R, by group
- Dealing with spaces and “weird” characters in column names with dplyr::rename()
- Filtering rows in R unexpectedly removes NAs when using subset or dplyr::filter