I have the following DF (example data, my actual data set is 96 columns):
class X1A X1B X2A X2B X3A X3B X4A X4B X5A X5B X6A X6B
1 A 0 1 0 0 0 0 0 1 1 1 1 1
2 B 1 1 1 1 0 0 0 1 1 1 0 1
3 C 0 0 0 1 1 0 0 0 1 1 0 0
4 D 0 0 0 1 1 0 1 0 1 0 0 0
5 A 0 1 1 1 0 0 0 1 1 1 1 1
6 B 0 0 1 1 0 0 0 1 1 1 0 1
7 C 0 0 0 1 1 0 0 0 1 1 0 0
8 D 0 0 0 1 1 0 1 0 1 0 0 0
9 A 0 1 1 1 0 0 0 1 1 1 1 1
10 B 1 1 1 1 0 0 0 1 1 1 0 1
11 C 0 0 0 1 1 0 0 0 1 1 0 0
12 D 0 1 0 1 1 0 1 0 1 0 0 0
Class denotes the phylogenic class of the organism (each replicate of the letter is a different species but members of the same class). 1A and 1B are samples from the same site. I want to combine the two presence/absence data (1/0 respectively) from each two samples from every site and add up the number of "presences" for the class across that site. so that my df now looks something like this:
Sample Class Number of Species Present
1 A 3
1 B 2
1 C 0
1 D 1
2 A 2
2 B 3
2 C 3
2 D 3
For example, in the original df you see that Class C species are not present in sample 2A at all but each species of class C is present in sample 2B. So the output df records Species C as present 3 times in sample 2. Furthermore, Class B has 3 different species occur in 2A and in 2B but because they are replicates of the output df records sample 2 as having 3 Class B species present.
Any help would be appreactiated as I'm stumped!
Cheers!!
Read more here: https://stackoverflow.com/questions/67001957/is-there-an-r-function-for-combining-two-replicate-site-columns-in-a-table-to-sh
Content Attribution
This content was originally published by Jarrod Cameron at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.