「WebTobinQ/Example」の編集履歴(バックアップ)一覧はこちら
WebTobinQ/Example - (2011/09/10 (土) 00:51:21) の1つ前との変更点
追加された行は緑色になります。
削除された行は赤色になります。
[[WebTobinQ]]
このページは実際に動いたコードを蓄積しています。
実際のサイト、http://webtobinq.appspot.com/ に行って、以下のコードをコピペしてみてEval Allしたり、一行ずつ末尾でEnterしたりしてみて下さい。
*** vectorかけるスカラー
3*c(1, 2, 3)
*** ただのplot
x <- 1:10
y <- 1:10
plot(x, y)
*** plot、lines、vector計算
year <- c(1980,1981,1982,1983,1984,1985,1986,1987,1988,1989,1990,1991,1992,1993,1994,1995,1996,1997,1998,1999,2000)
gdp <- c(312712.7, 321490.5, 331710.7, 339823.8, 353436.2, 368184.1, 379895.7, 399442.3, 424657.3, 445468.8, 469780.5, 481660.7, 483375.6, 485498.4, 490730.7, 502794.3, 520053.8, 521315.1, 518380.7, 525695.8, 530312.8)
cons <- c(174382.7, 177074.9, 184799.3, 189292.0, 194237.4, 201627.8, 209050.0, 217356.6, 229129.5, 238784.9, 248840.1, 256905.6, 261560.2, 266385.2, 272342.2, 277906.5, 284766.8, 281393.7, 285094.0, 289454.2, 288981.1)
growth.gdp<-(gdp[2:21]-gdp[1:20])/gdp[2:21]*100
growth.cons<-(cons[2:21]-cons[1:20])/cons[2:21]*100
plot(year[2:21],growth.gdp)
lines(year[2:21],growth.cons)
*** mean, sqrt, var, <=, >
year <- c(1980,1981,1982,1983,1984,1985,1986,1987,1988,1989,1990,1991,1992,1993,1994,1995,1996,1997,1998,1999,2000)
gdp <- c(312712.7, 321490.5, 331710.7, 339823.8, 353436.2, 368184.1, 379895.7, 399442.3, 424657.3, 445468.8, 469780.5, 481660.7, 483375.6, 485498.4, 490730.7, 502794.3, 520053.8, 521315.1, 518380.7, 525695.8, 530312.8)
growth.gdp<-((gdp[2:21]-gdp[1:20])/gdp[2:21])*100
ysub<-seq(1981,2000)
mean(growth.gdp[ysub<=1989])
sqrt(var(growth.gdp[ysub<=1989]))
mean(growth.gdp[ysub>1989])
*** read.server, data.frame関連
**** 消費とgdpをplotしてみる
df <- read.server("http://webtobins.appspot.com/t/", "実質GDP", c("Fiscal Year", "GDP(expenditure approach)", "PrivateConsumption"), num=30)
plot(df[["Fiscal Year"]],df[["GDP(expenditure approach)"]],ylim=c(100000,600000))
lines(df[["Fiscal Year"]],df[["PrivateConsumption"]])
**** 1980年代とそれ以降のgdp成長率の平均値を見る
df <- read.server("http://webtobins.appspot.com/t/", "実質GDP", c("Fiscal Year", "GDP(expenditure approach)", "PrivateConsumption"), num=30)
gdp <- df[["GDP(expenditure approach)"]]
growth.gdp<-((gdp[2:30]-gdp[1:29])/gdp[2:30])*100
ysub<-seq(1982,2010)
mean(growth.gdp[ysub<=1989])
mean(growth.gdp[ysub>1989])
*** for文、etc. 1983年以降の失業率をplot。月次データから年次データに変換
df <- read.server("http://webtobins.appspot.com/t/", "完全失業率(季節調整済み)", c("Year", "Month", "男女計: Total"), range=c(1983, 2010), num=1000)
totalName <- "男女計: Total"
total <- df[[totalName]]
n <- (length(total)/12)
y <- 1:n
for(i in 1:n) { b <- (12*(n-i))+1; e <- (12*(n-i))+12; y[i] <- mean(total[b:e]) }
plot(1983:(1983+n-1), y, main="失業率(季節調整済み)", type="l")
#ref(unemployment.gif)
他
[[WebTobinQ]]
このページは実際に動いたコードを蓄積しています。
実際のサイト、http://webtobinq.appspot.com/ に行って、以下のコードをコピペしてみてEval Allしたり、一行ずつ末尾でEnterしたりしてみて下さい。
*** vectorかけるスカラー
3*c(1, 2, 3)
*** ただのplot
x <- 1:10
y <- 1:10
plot(x, y)
*** plot、lines、vector計算
year <- c(1980,1981,1982,1983,1984,1985,1986,1987,1988,1989,1990,1991,1992,1993,1994,1995,1996,1997,1998,1999,2000)
gdp <- c(312712.7, 321490.5, 331710.7, 339823.8, 353436.2, 368184.1, 379895.7, 399442.3, 424657.3, 445468.8, 469780.5, 481660.7, 483375.6, 485498.4, 490730.7, 502794.3, 520053.8, 521315.1, 518380.7, 525695.8, 530312.8)
cons <- c(174382.7, 177074.9, 184799.3, 189292.0, 194237.4, 201627.8, 209050.0, 217356.6, 229129.5, 238784.9, 248840.1, 256905.6, 261560.2, 266385.2, 272342.2, 277906.5, 284766.8, 281393.7, 285094.0, 289454.2, 288981.1)
growth.gdp<-(gdp[2:21]-gdp[1:20])/gdp[2:21]*100
growth.cons<-(cons[2:21]-cons[1:20])/cons[2:21]*100
plot(year[2:21],growth.gdp)
lines(year[2:21],growth.cons)
*** mean, sqrt, var, <=, >
year <- c(1980,1981,1982,1983,1984,1985,1986,1987,1988,1989,1990,1991,1992,1993,1994,1995,1996,1997,1998,1999,2000)
gdp <- c(312712.7, 321490.5, 331710.7, 339823.8, 353436.2, 368184.1, 379895.7, 399442.3, 424657.3, 445468.8, 469780.5, 481660.7, 483375.6, 485498.4, 490730.7, 502794.3, 520053.8, 521315.1, 518380.7, 525695.8, 530312.8)
growth.gdp<-((gdp[2:21]-gdp[1:20])/gdp[2:21])*100
ysub<-seq(1981,2000)
mean(growth.gdp[ysub<=1989])
sqrt(var(growth.gdp[ysub<=1989]))
mean(growth.gdp[ysub>1989])
*** read.server, data.frame関連
**** 消費とgdpをplotしてみる
df <- read.server("http://webtobins.appspot.com/t/", "実質GDP", c("Fiscal Year", "GDP(expenditure approach)", "PrivateConsumption"), num=30)
plot(df[["Fiscal Year"]],df[["GDP(expenditure approach)"]],ylim=c(100000,600000))
lines(df[["Fiscal Year"]],df[["PrivateConsumption"]])
**** 1980年代とそれ以降のgdp成長率の平均値を見る
df <- read.server("http://webtobins.appspot.com/t/", "実質GDP", c("Fiscal Year", "GDP(expenditure approach)", "PrivateConsumption"), num=30)
gdp <- df[["GDP(expenditure approach)"]]
growth.gdp<-((gdp[2:30]-gdp[1:29])/gdp[2:30])*100
ysub<-seq(1982,2010)
mean(growth.gdp[ysub<=1989])
mean(growth.gdp[ysub>1989])
*** for文、etc. 1983年以降の失業率をplot。月次データから年次データに変換
df <- read.server("http://webtobins.appspot.com/t/", "完全失業率(季節調整済み)", c("Year", "Month", "男女計: Total"), range=c(1983, 2010), num=1000)
totalName <- "男女計: Total"
total <- df[[totalName]]
n <- (length(total)/12)
y <- 1:n
for(i in 1:n) { b <- (12*(n-i))+1; e <- (12*(n-i))+12; y[i] <- mean(total[b:e]) }
plot(1983:(1983+n-1), y, main="失業率(季節調整済み)", type="l")