Skip to content

Instantly share code, notes, and snippets.

@mutolisp
Last active October 13, 2020 14:39
Show Gist options
  • Save mutolisp/4898bb2e25a33487385bf5ede8e553da to your computer and use it in GitHub Desktop.
Save mutolisp/4898bb2e25a33487385bf5ede8e553da to your computer and use it in GitHub Desktop.
Group calculation of R
mountain aspect species cover r
SEN W11 A 30 1
SEN W11 B 10 3
SEN W11 C 0.5 2
SEN W13 A 15 4
SEN W13 D 5 3
SEN W13 E 3 2
SEN W13 F 0.1 1
SEN W13 G 10 4
SUN E11 A 15 2
SUN E11 B 5 3
SUN E11 C 0.5 2
SUN E11 E 1 4
SUN S13 D 35 1
SUN S13 E 10 1
SUN S13 F 5 2
SUN S13 G 1 4
library(data.table)
exampleFile <- 'https://gist.githubusercontent.com/mutolisp/4898bb2e25a33487385bf5ede8e553da/raw/f101cc6e126eb2475d2345377bd02bbee3474799/dummy.csv'
dummy <- fread(exampleFile, sep = ',', header = T)
# calculate cover summation by mountain and aspect
dummy[, sum(cover), by = .(mountain, aspect)]
# calculate thermophilization indicator
Tsi <- dummy[, sum(cover*r)/sum(cover), by = .(mountain,aspect) ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment