R is suitable for data analysis and we can use R to do machine learning after mining the data from STEEMSQL. The first step is to connect to STEEMSQL, and let’s do it.
Step 1 – Install the MS SQL package
@arcange ‘s STEEMSQL is a Microsoft SQL Server, thus we need R to be able to handle the MSSQL connection via the RODBC library. To install the connector in R, run the following command
install.packages("RODBC")
Step 2 – Reference the RODBC library
After RODBC is installed, you first need to reference it e.g. in R script.
library(RODBC)
Step 3 – Connect via odbcDriverConnect method
Like other programming language, RODBC has a DB-connect method, i.e. odbcDriverConnect which needs to be customised to the following according to STEEMSQL:
conn <- odbcDriverConnect("Driver=SQL Server Native Client 11.0;Server=sql.steemsql.com;Database=DBSteem;Uid=steemit;Pwd=steemit")
Upon success, the connection is stored in conn.
Step 4 – Run the SQL query
This is easy to understand, first parameter is the db connection and the second parameter is the actual SQL statement!
sqlQuery(conn, str_c("select voting_power from Accounts where name='justyy'"))
Demo R Function – Get Current Voting Power
Let’s wrap this up!
library(RODBC) library(stringr) getvp = function(id) { conn <- odbcDriverConnect("Driver=SQL Server Native Client 11.0;Server=sql.steemsql.com;Database=DBSteem;Uid=steemit;Pwd=steemit") x <- sqlQuery(conn, str_c("select voting_power from Accounts where name='", id, "'")) close(conn) return(x) }
You may also like: R 教程之 怎么样连接到 STEEMSQL 数据库
R Tutorial
- R Tutorial – Map, Filter, Reduce, Lambda
- R Tutorial – Monte Carlo
- R Tutorial – Permutation
- R Tutorial – Sigmoid
- R Tutorial – Connecting to STEEMSQL via RODBC
- R Tutorial – How rich is SteemIt Wechat Group?
- R Tutorial – Knowing when a Steem Whale vote?
- R Tutorial – How to Connect to SteemSQL via RStudio?
- R Tutorial – Using R to Fit Linear Model – Predit Weight over Height
–EOF (The Ultimate Computing & Technology Blog) —
loading...
Last Post: SteemIt: Javascript Function to Get Original Post from Comment's PermLink
Next Post: R Tutorial - How rich is SteemIt Wechat Group?
Great resource. Thanks. You misspelled “RODBC” in the first line of code though, which resulted in about 3 minutes of frustration for me.
Thanks, corrected. 🙂