Data Analysis/R
R : XML 데이터를 Parsing하여 데이터로 처리하기
불탄오징어
2013. 11. 15. 23:01
이브온라인 팬사이트 중에서 게임 내 마켓 정보를 담아 놓은 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