Title: | Korean Statistical Information Service (KOSIS) |
---|---|
Description: | API wrapper to download statistical information from the Korean Statistical Information Service (KOSIS) <https://kosis.kr/openapi/index/index.jsp>. |
Authors: | Seokhoon Joo [aut, cre] |
Maintainer: | Seokhoon Joo <[email protected]> |
License: | MIT + file LICENSE |
Version: | 0.0.1 |
Built: | 2024-11-20 05:35:37 UTC |
Source: | https://github.com/seokhoonj/kosis |
API wrapper to download statistical information from the Korean Statistical Information Service (KOSIS) https://kosis.kr/openapi/index/index.jsp.
To use this package, you will first need to get your API key from the
website https://kosis.kr/openapi/index/index.jsp. Once you have your
key, you can save it as an environment variable for the current session
using the kosis.setKey
function. Alternatively, you can set it
permanently by adding the following line to your .Renviron file:
KOSIS_API_KEY = PASTE YOUR API KEY
Any functions that require your API key try to retrieve it via
Sys.getenv("KOSIS_API_KEY")
(unless API key is explicitly specified as
a function argument).
Maintainer: Seokhoon Joo [email protected]
Cast Item variable from the stat data downloaded from getStatData function
castItem(statData, itemVar = c("ITM_NM", "ITM_ID", "ITM_NM_ENG"))
castItem(statData, itemVar = c("ITM_NM", "ITM_ID", "ITM_NM_ENG"))
statData |
A data.frame downloaded from getStatData function |
itemVar |
A string specifying item variable |
## Example statData <- getStatData(orgId = "101", tblId = "DT_1B41", objL1 = "ALL") castItem(statData = statData, itemVar = "ITM_NM")
A data.frame object containing queried information
KOSIS Statistic Data
getStatData( orgId, tblId, prdSe = c("Y", "H", "Q", "M", "D", "IR"), startPrdDe, endPrdDe, newEstPrdCnt = 3, prdInterval = 1, itmId = "ALL", objL1 = "ALL", objL2 = "", objL3 = "", objL4 = "", ... )
getStatData( orgId, tblId, prdSe = c("Y", "H", "Q", "M", "D", "IR"), startPrdDe, endPrdDe, newEstPrdCnt = 3, prdInterval = 1, itmId = "ALL", objL1 = "ALL", objL2 = "", objL3 = "", objL4 = "", ... )
orgId |
A string specifying the organization id |
tblId |
A string specifying the table id |
prdSe |
A string specifying the period symbol (Y, H, Q, M, D, IR: Irregularly) |
startPrdDe |
A string specifying start period (format: YYYY, YYYYMM(MM:01~12), YYYYHH(HH:01,02), YYYYQQ(QQ:01~04), YYYYMMDD) |
endPrdDe |
A string specifying end period (format: YYYY, YYYYMM(MM:01~12), YYYYHH(HH:01,02), YYYYQQ(QQ:01~04), YYYYMMDD) |
newEstPrdCnt |
A string specifying newest period count |
prdInterval |
A string specifying period interval |
itmId |
A string item id |
objL1 |
A string specifying object level 1 |
objL2 |
A string specifying object level 2 |
objL3 |
A string specifying object level 3 |
objL4 |
A string specifying object level 4 |
... |
A string specifying object level 5, 6, 7, 8 (objL5, objL6, objL7, objL8) |
## Example getStatData(orgId = "101", tblId = "DT_1B41")
A data.frame object containing queried information
KOSIS Statistic Data from URL
getStatDataFromURL(url)
getStatDataFromURL(url)
url |
A string specifying the KOSIS URL |
## Example url <- "https://kosis.kr/openapi/Param/statisticsParameterData.do? method=getList&apiKey=& itmId=T6+T16+T26+T5+T15+T25+T2+T12+T22+T3+T13+T23+T4+T14+T24+T1+T11+T21+& objL1=ALL&objL2=&objL3=&objL4=&objL5=&objL6=&objL7=&objL8=& format=json&jsonVD=Y& prdSe=Y&newEstPrdCnt=3&prdInterval=1& orgId=101&tblId=DT_1B41" getStatDataFromURL(url = url)
A data.frame object containing queried information
KOSIS Statistic Explanation
getStatExpl(orgId, tblId, statId, metaItm = "ALL")
getStatExpl(orgId, tblId, statId, metaItm = "ALL")
orgId |
A string specifying the organization id |
tblId |
A string specifying the table id |
statId |
A string specifying the stat id |
metaItm |
A string specifying the meta item |
## Example getStatExpl(orgId = "101", tblId = "DT_1L9V054") getStatExpl(statId = "1962009")
A data.frame object containing queried information
KOSIS Statistic List
getStatList( vwCd = c("MT_ZTITLE", "MT_OTITLE", "MT_GTITLE01", "MT_GTITLE02", "MT_CHOSUN_TITLE", "MT_HANKUK_TITLE", "MT_STOP_TITLE", "MT_RTITLE", "MT_BUKHAN", "MT_TM1_TITLE", "MT_TM2_TITLE", "MT_ETITLE"), parentListId = "" )
getStatList( vwCd = c("MT_ZTITLE", "MT_OTITLE", "MT_GTITLE01", "MT_GTITLE02", "MT_CHOSUN_TITLE", "MT_HANKUK_TITLE", "MT_STOP_TITLE", "MT_RTITLE", "MT_BUKHAN", "MT_TM1_TITLE", "MT_TM2_TITLE", "MT_ETITLE"), parentListId = "" )
vwCd |
A string specifying the view code |
parentListId |
A string specifying the parent list id |
## Example getStatList(vwCd = "MT_ZTITLE", parentListId = "") getStatList(vwCd = "MT_ZTITLE", parentListId = "F") getStatList(vwCd = "MT_ZTITLE", parentListId = "F_29")
A data.frame object containing queried information
KOSIS Statistic Meta
getStatMeta( orgId, tblId, type = c("TBL", "ORG", "PRD", "ITM", "CMMT", "UNIT", "SOURCE", "WGT", "NCD") )
getStatMeta( orgId, tblId, type = c("TBL", "ORG", "PRD", "ITM", "CMMT", "UNIT", "SOURCE", "WGT", "NCD") )
orgId |
A string specifying the organization id |
tblId |
A string specifying the table id |
type |
A string specifying the meta type |
## Example getStatMeta(orgId = "101", tblId = "DT_1IN0001") getStatMeta(orgId = "101", tblId = "DT_1IN0001", type = "ORG")
A data.frame object containing queried information
KOSIS Statistic Search
getStatSearch( searchNm, startCount = 1, resultCount = 20, sort = c("RANK", "DATE") )
getStatSearch( searchNm, startCount = 1, resultCount = 20, sort = c("RANK", "DATE") )
searchNm |
A string specifying a name you search |
startCount |
A nuemeric specifying a page number |
resultCount |
A numeric specifying counts of result (resultCount = 20, startCount = 2 : 21~40 Result) |
sort |
A string specifying the sorting (RANK: accuracy, DATE: newest) |
## Example getStatSearch(searchNm = "CPI")
A data.frame object containing queried information
Save KOSIS API key for the current session. To set it permanently, please add the following line to your .Renvrion file:
KOSIS_API_KEY = "YOUR API KEY"
kosis.setKey(apiKey) kosis.printKey()
kosis.setKey(apiKey) kosis.printKey()
apiKey |
A string specifying KOSIS API key |
No return value, called to set api key
## Set API Key for the current session kosis.setKey("your_api_key") ## Check API key kosis.printKey()
## Set API Key for the current session kosis.setKey("your_api_key") ## Check API key kosis.printKey()
Remove columns that consist of unique values
removeUniqueCols(statData)
removeUniqueCols(statData)
statData |
A data.frame downloaded from getStatData function |
## Example df <- removeUniqueCols(statData = statData)
A data.frame object with columns that consist of non-unique values