0

How do I replace all number >1 with 1 in a data frame. The data is to be converted to 1 to signify presence vs absence of species. The headings are:

Date Site Time New.File.Name Frame.Number File.Name Mantas IDs. Whale.Shark Thresher.Shark Tiger.Shark Turtle Hammer.Head Grey.Reef.Shark White.Tip.Reef.Shark

I have abundance and I am trying to convert to richness

> TN %>% mutate_if(is.numeric, ~1 * (. != 0)) #To convert all non-zero numeric values to 1
Error in TN %>% mutate_if(is.numeric, ~1 * (. != 0)) : 
  could not find function "%>%"

> TN -> mutate_if(is.numeric, ~1 * (. != 0)) #To convert all non-zero numeric values to 1 --> didnt work
Error in mutate_if(is.numeric, ~1 * (. != 0)) <- TN : 
  could not find function "mutate_if<-"
  • Did you run `library(dplyr)` before running that code? – Jilber Urbina Nov 16 '22 at 23:41
  • Greetings! Usually it is helpful to provide a minimally reproducible dataset for questions here so people can troubleshoot your problems (rather than a table or screenshot for example). One way of doing is by using the `dput` function on the data you are using and pasting the output into your question. You can find out how to use it here: https://youtu.be/3EID3P1oisg – Shawn Hemelstrand Nov 17 '22 at 01:08
  • Related: ["_How to make a great R reproducible example_"](https://stackoverflow.com/q/5963269/11107541). – starball Nov 29 '22 at 22:37

0 Answers0