Rahul Garg
July 13, 2020
head(gdp)
CHN IND USA ts
X1970 19.30 5.1572297 -0.2540796 1
X1971 7.06 1.6429304 3.2933624 2
X1972 3.81 -0.5533013 5.2588954 3
X1973 7.76 3.2955211 5.6457195 4
X1974 2.31 1.1853363 -0.5405465 5
X1975 8.72 9.1499120 -0.2054640 6
Notably, ts represents the number of year from 1970 to 2019 (starting from 1). The row name contains the real year.
This code is for internal processing of GDP data.
plot1 <- plot_ly()
plot1 <- plot1 %>%
add_trace(x = ~gdp[,4], y = ~gdp[,1], type = "scatter", mode = "Lines", name = "China") %>%
add_trace(x = ~gdp[,4], y = ~gdp[,2], type = "scatter", mode = "Lines", name = "India") %>%
add_trace(x = ~gdp[,4], y = ~gdp[,3], type = "scatter", mode = "Lines", name = "USA")
The previous code leads to following plot output -
<!–html_preserve–>
meanx <- as.data.frame(cbind(c("China", "India", "USA"),c(0,0,0)))
meanx[,2] <- as.numeric(as.character(meanx[,2]))
if (chn) {meanx[1,2] <- mean(gdp[,1])}
if (ind) {meanx[2,2] <- mean(gdp[,2])}
if (usa) {meanx[3,2] <- mean(gdp[,3])}
colnames(meanx) <- c("country", "Average GDP growth rate")
meanx
country Average GDP growth rate
1 China 9.033272
2 India 5.482645
3 USA 2.746236