Linux system users need to install other extension packages when using R language to connect to SQL database. So, should we use ODBC to install or use DBI to install? Today, Xiaobian will give you an analysis of the difference between the two installation methods.
Data analysis often need to get data from the outside. In many cases, the data is stored in a relational database. In general, we can use SQL to extract the required data, save it as text and read it in by R. This approach combines the storage capacity of the database with the analytical capabilities of R, and is also very fast. But if you want to form a set of repetitive automated workflows, you can connect R to an external database, manipulate the database directly in R, and generate the final result, which is also a viable approach.
Connecting to the database in R requires the installation of other extension packages. Depending on the connection method, we have two options: one is ODBC, you need to install the RODBC package and install the ODBC driver. The other is the DBI mode, which installs the driver based on the type of database already installed. Because the latter retains the original features of each database, individuals prefer to use the DBI connection. There are several main packages below that provide DBI connectivity: RMySQL, RSQLite, ROracle, RPostgreSQL. It can be seen from the names that they correspond to several mainstream databases.
In these databases, SQLite is a lightweight database that is completely free, easy to use, does not require installation, does not require any configuration, and does not require an administrator. If you only need local stand-alone operation, it is very convenient to use it to access data with R. Let's take a look at an example of operating a SQLite database in R.
Starting from scratch:
1. Download SQLite, which is a separate executable file and is operated from the command line. If you are not used to installing a GUI such as sqlitebrowser. Put it in a folder first, such as sqlite.
2, execute the sql script in sqlite, create a database. Put the script file in the same folder and do the following. There should now be a database file for train.db in the folder.
.read Scheme.sql
.read Data.sql
.backup train.db
3. Install the RSQlite package in R
install.packages(‘RSQlite’)
4, load the RSQlite package, use SQL to read the data after the connection is established
library(RSQLite)
#Create Connection, pay attention to database type and file address
con "- dbConnect(‘SQLite’, dbname=‘d:/sqlite/train.db’)
# Observe three in the database Data Table
dbListTables(con)
# Observe the fields of one of the tables
dbListFields(con, ‘Apply’)
# Write a SQL Statement to select the required data
sql "- “select sName, GPA, decision,cName
from Student, Apply
where Student.sID = Apply.sID
and sizeHS 1000 and major = ‘CS’ and cName = ‘Stanford’”
# will select the data Enter data and display it at the same time
(data "- dbGetQuery(con, sql))
# Close database connection
dbDisconnect(con)
The above is the difference between using ODBC to install and using DBI to install the extension package. Users who need it can check out this article.
With the widespread use of the Linux operating system, the security problems faced by the system hav
KVM is a virtual machine, mainly used in Linux systems. How do you install KVM on a
In the Linux system file structure, there is such a magical directory that is usr.
selinux is a Linux security subsystem, is a mandatory access control security module, then how to sh
Linux system xinetd service can not start how to do?
Linux system yum command function introduction
Kali Linux installation Google Chrome common problems and solutions
Linux system startx command function and usage
How Linux implements the transmission of UDP broadcast messages
Baidu network disk bcloud common problem solution in Linux
Linux change 22 port method summary
Steps to install Brackets on Ubuntu
What are the SELinux security mechanisms?
How to mount/uninstall USB devices using commands under Linux
Linux uses Tmux to improve the efficiency of terminal operations.
How does Win10 turn off the positioning function? Win10 method of closing location service
Microsoft anti-piracy black screen solution
Implementing RAID functions in software under Linux (1)
What can I do if Win8 cannot find a super administrator account?
The reason why the sharing system can't browse the webpage and the solution
Under the Win 7 system, the router is still set up correctly and still cannot access the Internet.
How to optimize the firewall function of Win7 system
Solution for Win8's Win+X command cannot be called
Rainforest woodwind win7 Ultimate system set the screensaver as a desktop wallpaper trick