I am very new to R and have a simple question. I need to use the SPEI package and generate the Standardized Precipitation Index using a panel data set of (panel=310 and t=1900 to 2015). I follow the article “How to use: Package 'SPEI' for basic calculations”. I am able to replicate it with my data. This is the code that I run
library(haven)
mydata<-read_dta("/Users/pc/Desktop/R/RAIN.dta")
library(SPEI)
SPI3 = spi(mydata$RF, scale = 3, distribution = 'Gamma')
plot(SPI3)
I see my data listed in the ‘environment window’ on the top right and I see the SPI3 index listed below it. However, I need the index to be generated ‘within the data set’ as an additional variable. That is evidently not the case and I don’t know how to get the index in my dataset. I realize that I have probably not ‘defined’ the data set and/or the new variable to be included in it but can’t get how to do so.