무회blog

R함수 basic004 : substr, sub, replace, regmatches, 매칭 데이터 패턴 지우고 수정 ,등등 본문

Python/R

R함수 basic004 : substr, sub, replace, regmatches, 매칭 데이터 패턴 지우고 수정 ,등등

최무회 2020. 6. 3. 21:21
## string Data 처리 방식 (최신테스트 내용 최상위 배치)
ttx04_cn <- 
"聚水潭聚水潭成立于2014年1月,创建之初,以电商SaaSERP切入市场
,如今已经发展成为以SaaSERP为核心,集多种商家服务为一体的SaaS协同平台
,为全国近50万家电商企业提供综合的信息化解决方案。聚水潭创始人兼CEO骆海东表示:
“本轮募集资金将用于产品和服务体系的升级和优化、协同供应链的打造、海外市场的拓展以及SaaS协同生态的投资和并购。”"

ttx04_en <- 
"Rich countries are set to take on at least $17tn of extra public debt as they battle the economic consequences of the pandemic, 
according to the OECD, as sharp drops in tax revenues are expected to dwarf the stimulus measures put in place to battle the disease.
Across the OECD club of rich countries, average government financial liabilities are expected to rise from 109 per cent of gross domestic product to more than 137 per cent this year
, leaving many with public debt burdens similar to the current level in Italy.
Additional debt of that scale would amount to a minimum of $13,000 per person across the 1.3bn people that live in OECD member countries. 
Debt levels could rise even further if the economic recovery from the  OECD pandemic is OECDslower than many economists hope."

ttx04_ko <-
"앞서 원-핫 인코딩 챕터에서 aaaa 찾기 원-핫 벡터는 aaaaaa없애기 단어 간 찾기 유사도를 계산할 수 없다는 단점이 있음을 언급한 적이 있습니다. 
그래서 단어찾기 간 찾기 유사도를 반영할 수 있도록 찾기 단어의aaaaa없애기 의미를aaaaaaaaaaa없애기 벡터화 할 수 있는 방법이 필요합니다. "

ttx04_cn
ttx04_en
ttx04_ko

패턴 <- regexpr('없애기',ttx04_ko)
regmatches(ttx04_ko,패턴)   # 패턴만 뽑아내기 
regmatches(ttx04_ko,패턴,invert = T)   # 패턴만 지우고 뽑아내기 
regmatches(ttx04_ko,패턴,invert = T)[[1]]   # 패턴만 지우고 뽑아내기 
regmatches(ttx04_ko,패턴,invert = T)[[1]][1]   # 패턴만 지우고 뽑아내기 

substr(ttx04_en,1,30)                                # 1~30 개 문자열 추출 
sub("OECD",replacement = "--------",ttx04_en)        #  replace 
Comments