I'm conducting an analysis on native/non-native cover in a restoration site. The data is organized by Polygon, then transect, then pin. I don't care if a certain pin has 1 native or 3 native species - I just care if it has any. Right now the raw data looks like this:
In the end, I want my data to look like this format:
The problem is that right now my code is counting every single entry for native, non native etc. And summing them for each transect. However, I want it to sum the number of pins total that have a native/non-native/etc. Regardless of how many there are. So for example, if pin 5 has 3 natives, I still would just want that to count as 1 native in the final table. Can anyone help? Code below, can't share the data though:
mynewtable <- data %>%
count(polygon_id, transect, native_non_native) %>%
spread(native_non_native, n)