R study Notes (1) 2015-4-23

Source: Internet
Author: User

1, R connection database

Step1: Download Rodbc. In console: Install.packages ("RODBC")

The downloaded RODBC package needs to be loaded into the rstudio before use. Tools->import Dataset.

Specify DSN: Call Odbcad32.exe (typically under C:\Windows\System32), click Add, select MySQL ODBC 5.2 ANSI Driver (choose a different drive depending on MySQL), and fill in the configuration as prompted. Application--Complete.

Step2:library (RODBC):

Mysql<-odbcconnect ("Baidu_lbs_data", uid= "root", pwd= "");

Baidu_lbs_data for Database name

SqlTables (MySQL); To read a table in a database

SQLQuery (MySQL, "select * from XXX"); SELECT statement

Sqldrop (MySQL, "XXX");//Delete table

Odbcclose (MySQL);//Close Database

SqlFetch (MySQL, "XXX", Rownames = "state")//contents of the output table

Data (XXX)//write table to database

Sqlsave (mysql,xxx,rownames = "state", ADDPK = TRUE)//Save data stream, new XX table

RM (XXX)

2. R Drawing

Plot ()

Lines when you draw multiple lines in a diagram

Grid adding rasters to graphs

Abline Add a line

Legend adding a legend

Save a picture in a corresponding format

such as PNG (file= "Myplot.png", bg= "Transparent"), #R code Dev.off ( ) jpeg (file= "myplot.jpeg") #R code Dev.off ( ) PDF (file= "myplot.pdf") #R Code Dev.off ()

Note: Dev is device

3.

R study Notes (1) 2015-4-23

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.