Hi, I am new to R. I have a matrix of 10 rows and 20 columns that represents vegetation data collected from 10 sites over a 20 year period. Each column represents a year for each of the 10 sites. I would like to assess changes between two periods (1-10 and 11-20) by calculating the difference between averages of the beginning (1-10) and end (11-20). I would then like to calculate the standard deviation as a function of the severity of these changes. I hope this makes sense. I would like to create a script that does the following:
-
Calculate the mean and standard deviation for each row of the first 10 years (mean and standard deviation of rows from amp.1 to amp.10)
-
Calculate the mean and standard deviation for each row of the remaining 10 years (mean and standard deviation of rows from amp.11 to amp.20). Note that columns 19 and 20 contain NAs but they should still be used in the calculation of the mean and sd.
-
Subtract the mean in 1 from the mean in 2 (2-1) and subtract the sd in 1 from the sd in 2.
-
Final output is a matrix with 10 rows and names of the following columns: mean 1-10, sd 1-10, mean 11-20, sd 11-20, a column of the difference of the means, and column of the difference of the sd. I am hoping to use the 'difference of the sds' column as a function to scale the severity of the changes obtained in the 'difference of the means' column. Not sure this is right but I would like to show how severe/widespread the changes estimated from the 'difference of the means' column are, over 20 years using sd.
I have provided a reprex of the dataset.
Thanks in advance
Edward
library(reprex)
ampdata <- readRDS("C:/Users/bt715205/Documents/Edward/eddy/ampdata.rds")
head(ampdata)
#> amp.1 amp.2 amp.3 amp.4 amp.5 amp.6 amp.7
#> [1,] 0.06355208 0.01929583 0.05010625 0.07260833 0.1451646 0.2267583 0.1553229
#> [2,] 0.04786250 0.06164375 0.07718125 0.12465000 0.1366375 0.3186677 0.2299771
#> [3,] 0.10436250 0.11362484 0.08359375 0.07995208 0.1058729 0.1818938 0.1076958
#> [4,] 0.19988125 0.29163542 0.14515000 0.15135313 0.1347437 0.2632969 0.2258917
#> [5,] 0.09733750 0.31862083 0.14447500 0.16182708 0.2022292 0.2894500 0.1968000
#> [6,] 0.15979063 0.23393229 0.12570625 0.11101667 0.1901313 0.2722760 0.1594500
#> amp.8 amp.9 amp.10 amp.11 amp.12 amp.13 amp.14
#> [1,] 0.09265000 0.1314458 0.12417917 0.22735000 0.07611458 0.06754583 0.0309750
#> [2,] 0.08024375 0.1006833 0.12896875 0.09196010 0.07724167 0.07230521 0.0399625
#> [3,] 0.07395422 0.1165167 0.05685625 0.08634375 0.09019375 0.15305208 0.1393375
#> [4,] 0.16513542 0.2381979 0.11930000 0.26552500 0.21667708 0.23057917 0.2556229
#> [5,] 0.23513793 0.2586385 0.18660417 0.23920625 0.14387292 0.15499583 0.1608542
#> [6,] 0.21845833 0.2316521 0.14089375 0.28081250 0.19513542 0.13513750 0.1778271
#> amp.15 amp.16 amp.17 amp.18 amp.19 amp.20
#> [1,] 0.11179479 0.03830000 0.01898021 0.16301042 NA NA
#> [2,] 0.18201907 0.05831875 0.09390000 0.18453646 NA NA
#> [3,] 0.09447812 0.08624375 0.11254063 0.08977708 NA NA
#> [4,] 0.17393333 0.15855208 0.16844375 0.14920625 NA NA
#> [5,] 0.15920625 0.17954583 0.15765417 0.14417500 NA NA
#> [6,] 0.15242396 0.14681875 0.26499271 0.15425000 NA NA
View(ampdata)
Created on 2021-02-04 by the reprex package (v1.0.0)