I have data.frame xwith the following format:
species site count
1: A 1.1 25
2: A 1.2 1152
3: A 2.1 26
4: A 3.5 1
5: A 3.7 98
---
101: B 1.2 6
102: B 1.3 10
103: B 2.1 8
104: B 2.2 8
105: B 2.3 5
I also have another data.frame areawith the following format:
species area
1: A 59.7
2: B 34.4
3: C 37.7
4: D 22.8
I would like to split the column count data.frame xby the values in the column area data.frame areawhen the values in the view column of each data.framecorrespond
I am trying to get it to work with a function ddply:
density = ddply(x, "species", mutate, density = x$count/area[,2]
But I can’t understand the correct index call syntax area[]to select only the row that matches the values found in x$species. However, I'm a super beginner in the package plyr(and apply*in general), so this may be a completely wrong approach
I hope to return the data.framefollowing format:
species site count density
1: A 1.1 25 0.419
2: A 1.2 152 2.546
3: A 2.1 26 0.436
4: A 3.5 1 0.017
5: A 3.7 98 1.641
---
101: B 1.2 6 0.174
102: B 1.3 10 0.291
103: B 2.1 8 0.233
104: B 2.2 8 0.233
105: B 2.3 5 0.145