통계분석툴 R & MongoDB 연동 방법

안녕하세요? NoSQL 전문가 주종면입니다.

이번 차수에서는 MongoDB를 통계분석 툴인 R을 통해 분석하고 결과를 출력하기위한 연동 방법에 대해 알아보도록 하겠습니다. 

 

먼저, MongoDB를 시작한 후 yield_historical.out  컬렉션에 저장된 데이터를 확인 하겠습니다.

 

> use mongo_hadoop

switched to dbmongo_hadoop 

> 

>db.yield_historical.out.find().pretty() 

{ "_id" : 1990,"value" : 8.552400000000002 } 

{ "_id" : 1991,"value" : 7.8623600000000025 } 

{ "_id" : 1992,"value" : 7.008844621513946 } 

{ "_id" : 1993,"value" : 5.866279999999999 } 

{ "_id" : 1994,"value" : 7.085180722891565 } 

{ "_id" : 1995,"value" : 6.573920000000002 } 

{ "_id" : 1996,"value" : 6.443531746031742 } 

{ "_id" : 1997,"value" : 6.353959999999992 } 

{ "_id" : 1998,"value" : 5.262879999999994 } 

{ "_id" : 1999,"value" : 5.646135458167332 } 

 

다음은 R을 실행한 후 MongoDB 관련 패키지를 설치한 후 yield_historical.out 컬렉션을 검색해보겠습니다.

 

 

$ R 

R version 3.0.1(2013-05-16) -- "Good Sport" 

Copyright (C) 2013 The RFoundation for Statistical Computing 

Platform:x86_64-w64-mingw32/x64 (64-bit) 

> 

>library("RMongo")                                   ß MongoDB 접속하기 위한 패키지 로더 

 

> mongo <-mongoDbConnect("mongo_hadoop") ß mongo_hadoop 데이터베이스 접속 

> result <-dbGetQuery(mongo, "yield_historical.out", "", 0, 10) 

 

                         ßyield_historical.out 컬렉션에서 10개의Document 검색

 

 

> result                    ß 결과 검색

 

    X_id    value

1  1990 8.552400

2  1991 7.862360 

3  1992 7.008845 

4  1993 5.866280 

5  1994 7.085181 

6  1995 6.573920 

7  1996 6.443532 

8  1997 6.353960 

9  1998 5.262880 

10 1999 5.646135 

 

// 다음은BARPLOT 함수를 이용하여 막대 그레프 형태의 분석 결과를 확인해 보겠습니다.

 

> barplot(result$value, main='Analysis Status By year',col=c("darkblue", "red"),names.arg=c("1990","1991", "1992","1993", "1994", "1995", "1996","1997", "1998", "1999"), beside=TRUE,xlab="PLAN Information Technology co.") 

 

R_CHART.png 

 

경축! 아무것도 안하여 에스천사게임즈가 새로운 모습으로 재오픈 하였습니다.
어린이용이며, 설치가 필요없는 브라우저 게임입니다.
https://s1004games.com

 

다음 문법은 통계분석 툴 R을 통해 MongoDB 내의 컬렉션에 데이터를 조작하는 방법입니다.

 

// TEST DB에 접속하여 EMPLOYEES컬렉션에 하나의 Document를 입력합니다.

// MongoDB에 접속하여 먼저EMPLOYEES 컬렉션의 상태를 확인한 후 다음 문장을 실행합니다. 

 

test.dbInsertDocument <- function(){

  mongo <-mongoDbConnect("test") 

  output <-dbInsertDocument(mongo, "employees", '{"empno" : 1101,"ename": "Joo JongMyun"}') 

 dbDisconnect(mongo) 

} 

 

test.dbInsertDocument()

mongo <- mongoDbConnect("test") 

output <- dbGetQuery(mongo, 'employees', '', 0 , 20) 

output 

  

// TEST DB에 접속하여 EMPLOYEES컬렉션에 하나의 Document를 삭제합니다.

 

test.dbRemoveQuery <- function(){ 

  mongo <-mongoDbConnect("test") 

  output <-dbRemoveQuery(mongo, "employees", '{"ename": "JooJongMyun"}') 

 dbDisconnect(mongo) 

} 

 

test.dbRemoveQuery() 

mongo <- mongoDbConnect("test") 

output <- dbGetQuery(mongo, 'employees', '', 0 ,20) 

output 

  

// TEST DB에 접속하여 EMPLOYEES컬렉션에 2개의 Document를 입력한 후

  "Ju"로 시작되는 이름을 가진 사원을 검색합니다. 

  

test.dbGetQuery <- function(){

  mongo <-mongoDbConnect("test")

  output <- dbInsertDocument(mongo,"employees", '{"ename": "Ju YoungHyun"}')

  output <-dbInsertDocument(mongo, "employees", '{"ename": "JooJongMyun"}')

  dbDisconnect(mongo)

}

  

test.dbGetQuery()

 mongo <- mongoDbConnect("test")

 output <- dbGetQuery(mongo, 'employees','{"ename": { "$regex": "Joo","$options": "m"} }')

 output

 

// TEST DB에 접속하여 EMPLOYEES컬렉션에서 ename 필드를 기준으로 올림차순으로 분류하여 출력합니다.

 

mongo <- mongoDbConnect("test")

output <- dbGetQuery(mongo, "employees",'{ "$query": {}, "$orderby": { "ename": 1 } }}') 

dbDisconnect(mongo) 

output 

 

[출처] http://www.pitmongo.co.kr/bbs/board.php?bo_table=h_file&wr_id=27&sfl=wr_subject&stx=mongodb&sop=and

 

 

본 웹사이트는 광고를 포함하고 있습니다.
광고 클릭에서 발생하는 수익금은 모두 웹사이트 서버의 유지 및 관리, 그리고 기술 콘텐츠 향상을 위해 쓰여집니다.
번호 제목 글쓴이 날짜 조회 수
공지 오라클 기본 샘플 데이터베이스 졸리운_곰 2014.01.02 86134
공지 [SQL컨셉] 서적 "SQL컨셉"의 샘플 데이타 베이스 SAMPLE DATABASE of ORACLE 가을의 곰을... 2013.02.10 78636
공지 [G_SQL] Sample Database 가을의 곰을... 2012.05.20 95362
864 [러닝 텐서플로]Chap06 - 텍스트2: word2vec, Bidirectional RNN, GRU, 임베딩 시각화 file 졸리운_곰 2020.12.28 1283
863 [러닝 텐서플로]Chap05 - 텍스트 1: 텍스트와 시퀀스 처리 및 텐서보드 시각화 file 졸리운_곰 2020.12.28 1058
862 [러닝 텐서플로]Chap04 - 합성곱 신경망 CNN file 졸리운_곰 2020.12.28 1145
861 Making TensorFlow Models Portable Using ONNX file 졸리운_곰 2020.12.24 4431
860 [러닝 텐서플로]Chap03 - 텐서플로의 기본 이해하기 file 졸리운_곰 2020.12.24 1476
859 [러닝 텐서플로]Chap02 - 텐서플로 설치 및 실행 file 졸리운_곰 2020.12.24 851
858 [러닝 텐서플로]Chap01 - 텐서플로 란? file 졸리운_곰 2020.12.24 1275
857 러닝 텐서플로 - 0 file 졸리운_곰 2020.12.24 1741
856 Prometheus Query(PromQL) 기본 이해하기 file 졸리운_곰 2020.12.17 1413
855 [인프라 모니터링 오픈소스] Prometheus 를 알아보자 file 졸리운_곰 2020.12.17 1906
854 Prometheus + Grafana 대시보드 file 졸리운_곰 2020.12.17 2488
853 Grafana란? file 졸리운_곰 2020.12.17 2158
852 [mongodb] Error: network error while attempting to run command 'isMaster' on host '127.0.0.1:27017' file 졸리운_곰 2020.12.16 1450
851 [mongodb] How to Update a Document in MongoDB using Java 졸리운_곰 2020.12.14 2327
850 [oracle] 오라클 merge into 간단설명 및 예제(sample) 졸리운_곰 2020.12.14 1148
849 [oracle, sql] 04 | MERGE문 졸리운_곰 2020.12.14 1162
» 통계분석툴 R & MongoDB 연동 방법 file 졸리운_곰 2020.12.12 1821
847 [오라클, oracle] ORA-00911 : 문자가 부적합합니다 v1.0 졸리운_곰 2020.12.11 1751
846 [oracle, 오라클] 테이블이 존재 하는데, ORA-00942 발생 file 졸리운_곰 2020.12.11 4055
845 [Java, MongoDB] Mapping a BSON MongoDB document to a MyClass.class object? 졸리운_곰 2020.12.09 1821
대표 김성준 주소 : 경기 용인 분당수지 U타워 등록번호 : 142-07-27414
통신판매업 신고 : 제2012-용인수지-0185호 출판업 신고 : 수지구청 제 123호 개인정보보호최고책임자 : 김성준 sjkim70@stechstar.com
대표전화 : 010-4589-2193 [fax] 02-6280-1294 COPYRIGHT(C) stechstar.com ALL RIGHTS RESERVED