반응형
이브온라인 팬사이트 중에서 게임 내 마켓 정보를 담아 놓은 http://eve-central.com/라는 사이트가 있다. 해당 사이트에서 API 형태로 마켓 정보를 XML 로 던져주는데 해당 값을 R로 데이터 프레임으로 처리하는 스크립트를 작성했다.
약간 저장 목적? ㅎ
require('XML') query = 'http://api.eve-central.com/api/quicklook?typeid=29668' plex_row <- xmlToList(query) # Buy order price plex.b <- plex_row$quicklook$buy_orders b.region <- sapply(plex.b, function(x) x$region) b.station_name <- sapply(plex.b, function(x) x$station_name) b.price <- sapply(plex.b, function(x) x$price) b.vol_remain <- sapply(plex.b, function(x) x$vol_remain) b.reported_time <- sapply(plex.b, function(x) x$reported_time) plex.buy <- data.frame( region = b.region, station_name = b.station_name, price = as.double(b.price), vol_remain = b.vol_remain, datetime = b.reported_time ) # sell order price plex.s <- plex_row$quicklook$sell_orders s.region <- sapply(plex.s, function(x) x$region) s.station_name <- sapply(plex.s, function(x) x$station_name) s.price <- sapply(plex.s, function(x) x$price) s.vol_remain <- sapply(plex.s, function(x) x$vol_remain) s.reported_time <- sapply(plex.s, function(x) x$reported_time) plex.sell <- data.frame( region = s.region, station_name = s.station_name, price = as.double(s.price), vol_remain = s.vol_remain, datetime = s.reported_time ) # 일자별 평균 판매가 attach(plex.buy) avg.buy <- aggregate(plex.buy[,'price'], by = list(substr(datetime,1,5)), FUN = mean, na.rm=TRUE ) detach(plex.buy) # 일자별 평균 매입가 attach(plex.sell) avg.sell <- aggregate(plex.sell[,'price'], by = list(substr(datetime,1,5)), FUN = mean, na.rm=TRUE ) detach(plex.sell)
Modified by 11/20/13
'Data Analysis > R' 카테고리의 다른 글
R : RJDBC를 이용한 Oracle 연결하기 (0) | 2013.11.27 |
---|---|
R : odbc를 사용하여 MSSQL 접속 (0) | 2013.11.18 |
R : Facebook 데이터로 Word Cloud 그리기.. (4) | 2013.09.24 |
R : R script에서 다른 R script 가지고 오기(Source) (0) | 2013.09.10 |
R : 문자로 된 날짜를 Date Type으로 변경하기(as.Date(), strptime()) (0) | 2013.09.09 |
댓글