통계분석툴 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 86191
공지 [SQL컨셉] 서적 "SQL컨셉"의 샘플 데이타 베이스 SAMPLE DATABASE of ORACLE 가을의 곰을... 2013.02.10 78669
공지 [G_SQL] Sample Database 가을의 곰을... 2012.05.20 95405
101 [NoSQL] 성공적인 NoSQL 도입을 위한 키포인트 : NoSQL 데이터 모델링 file 졸리운_곰 2024.08.10 1080
100 [NoSQL] [MongoDB] NOSQL 데이터 모델링 기법 살펴보기 file 졸리운_곰 2024.08.09 1003
99 [NoSQL][MongoDB] Truncate a collection 졸리운_곰 2023.06.04 1272
98 [NoSQL] MongoDB 인증 모드 (password) 설정 졸리운_곰 2023.03.26 1419
97 [NoSQL] [Redis] Redis Persistence(영속성) 졸리운_곰 2021.04.11 1644
96 [NoSQL] [Cloud] Redis 설치, 사용 방법, 데이터 백업을 위한 RDB & AOF 개념 및 간단한 Redis 사용 사례 연구 file 졸리운_곰 2021.04.11 1716
95 [mongodb , 몽고디비] How to Use MongoDB Comparison Query Operators in Java 졸리운_곰 2021.02.19 1508
94 [mongodb, 몽고디비] How do you query for “is not null” in Mongo? 졸리운_곰 2021.02.19 1268
93 [MongoDB] 확장 검색 쿼리 - Aggregation 파이프라인 스테이지(Pipline Stage)와 표현식 졸리운_곰 2021.02.16 1192
92 [MongoDB] 확장 검색 쿼리 - 범용 Aggregation 졸리운_곰 2021.02.16 1349
91 [MongoDB] 확장 검색 쿼리 - Aggregation의 목적 및 작동방식 file 졸리운_곰 2021.02.16 1068
90 [MongoDB] 확장 검색 쿼리 - 집계 파이프 라인연산자 종류 졸리운_곰 2021.02.16 1140
89 [MongoDB] 확장 검색 쿼리 - Aggregation 파이프라인 스테이지(Pipline Stage)와 표현식 졸리운_곰 2021.02.16 1299
88 [mongodb, 몽고디비 쿼리] Mongodb query on substring of a field 졸리운_곰 2021.02.16 1306
87 [mongodb]Spring boot와 mongoDB 연동하기 그리고 REST API 졸리운_곰 2021.01.21 1706
86 [WebApp / Express] 간단한 MongoDB Middleware 만들기 졸리운_곰 2020.12.29 1152
85 [mongodb] Error: network error while attempting to run command 'isMaster' on host '127.0.0.1:27017' file 졸리운_곰 2020.12.16 1450
84 [mongodb] How to Update a Document in MongoDB using Java 졸리운_곰 2020.12.14 2329
83 [Java, MongoDB] Mapping a BSON MongoDB document to a MyClass.class object? 졸리운_곰 2020.12.09 1821
82 [mongodb] MongoDB CRUD 동작의 이해 졸리운_곰 2020.12.07 1286
대표 김성준 주소 : 경기 용인 분당수지 U타워 등록번호 : 142-07-27414
통신판매업 신고 : 제2012-용인수지-0185호 출판업 신고 : 수지구청 제 123호 개인정보보호최고책임자 : 김성준 sjkim70@stechstar.com
대표전화 : 010-4589-2193 [fax] 02-6280-1294 COPYRIGHT(C) stechstar.com ALL RIGHTS RESERVED