R Language Learning Resources

Source: Internet
Author: User
Tags cos true true

Getting Started video tutorials

Basic R Language Course (1)-Quick Start for R language http://cos.name/videos/intro-2-r/

Code

#对象1 +1*3c (1,2,3,4,5) C (' HelloWorld ', ' I am a R user ') C ("hehe", "haha") 1:66:1exp (1:4) log (1:3) a<-c (1,2,3,4,5) a[1]a[ 1:3]A[-4]A>3A[A>3] #数组, types need to be consistent x<-1:12a<-array (X,c (3,4)) a[2,2]a[2,]a[,2] #数据框 (like database tables) city<-c (' AA ', ' BB ', ' cc ', ' dd ', ' EE ') age<-c (12,34,45,67,78) sex<-c (' F ', ' m ', ' f ', ' m ', ' F ') People<-data.frame (city,age,sex) Peoplepeople[2,3]people[,2]people$agepeople$age>30people[people$age>30,] #列表, length can be inconsistent mylist<-list (age, City,sex) Mylist#class (a) class (People) class (MyList) attributes (People) str (people) #了解对象详细情况


Run results

> #对象 > 1+1*3[1] 4> C (1,2,3,4,5) [1] 1 2 3 4 5> C (' HelloWorld ', ' I am a R user ') [1] "HelloWorld" "I am a R use  R "> C (" hehe "," haha ") [1]" hehe "" haha "> 1:6[1] 1 2 3 4 5 6> 6:1[1] 6 5 4 3 2 1> exp (1:4) [1] 2.718282 7.389056 20.085537 54.598150> Log (1:3) [1] 0.0000000 0.6931472 1.0986123> a<-c (1,2,3,4,5) > A[1][1] 1> a[1:3][1] 1 2 3> A[-4][1] 1 2 3 5> a>3[1] false false TRUE true> A[a>3][1] 4 5> > > #数组, Types need to be consistent > x<  -1:12> A<-array (X,c (3,4)) > A[2,2][1] 5> a[2,][1] 2 5 8 11> a[,2][1] 4 5 6> > > #数据框 (Similar database tables) > The city<-c (' AA ', ' BB ', ' cc ', ' dd ', ' ee ') > age<-c (12,34,45,67,78) > Sex<-c (' F ', ' m ', ' f ', ' m ', ' f ') > People   <-data.frame (City,age,sex) > People City age sex1 aa F2 BB M3 cc DD F4 EE 78 F> people[2,3][1] mlevels:f m> people[,2][1] (78> people$age[1), 78> people$age>30[ 1] FALSE true True true&Gt People[people$age>30,] city age sex2 BB M3 cc F4 dd M5 ee f> > > #列表, Length can be inconsistent with Gt Mylist<-list (Age,city,sex) > Mylist[[1]][1] [78[[2]][1] "AA" "BB" "CC" "dd" "ee" [[3]][1] "F" "M" "F" "M" " F "> > > #> Class (a) [1]" Matrix "> Class (People) [1]" Data.frame "> Class (MyList) [1]" list "> Attributes  (people) $names [1] "City" "Age" "Sex" $row. Names[1] 1 2 3 4 5$class[1] "Data.frame" > str (people) #了解对象详细情况 ' Data.frame ': 5 Obs. of 3 variables: $ city:factor W/5 levels "AA", "BB", "CC",..: 1 2 3 4 5 $ age:num ($ sex:factor) W/2 levels "F", "M": 1 2 1 2 1

R Language Beginner Course (2)-visual function http://cos.name/videos/r101-data-visualization-with-r/in R language

Code

#绘图包graphics (Basic), lattice (advanced), Ggplot2 (strong) #基本绘图函数x <-c (1,2,3,4,5) y<-c (2,4,2,4,5) #左边表示y, right means Xplot (y~x) # The default discrete point plot (y~x,type= ' L ') #lineplot (y~x,type= ' h ') #histhist (y) #直方图 # using the Lattice package library (lattice) num<-sample (1:3, size=50,replace=1) Barchart (num) stripplotdensityplotxyplothistgram#lattice package of three-dimensional graphics library (lattice) Wireframe#ggplot2 Package Library (GGPLOT2) p<-ggplot (...) Print (p) p<-p+  stat_smooth () +  geom_point () +  scale_color_manual () +  facet_wrap () +  opts () +  Labs ()



Basic R Language Course (3)-R Read Data http://cos.name/videos/r101-data-access/

Code

#控制台的输入x <-readline () #输入一行x <-scan () #输入多行 # Local file output output<-file (' E:/out.txt ') cat (1:100,sep= ' t ', file= Output) Close (output) #本地文件输入output <-file (' E:/out.txt ') Input<-scan (file=output) Close (output) #字符串的输入output <-file (' E:/out2.txt ') writelines (As.character (1:12), con=output) input<-readlines (output) #数据表的读写 ( Read.table and Write.table) write.table (iris,file= ' iris.csv ', sep= ', ') data<-read.table (file= ' iris.csv ', sep= ', ') Data<-read.table (File=file.choose (), sep= ', ') data<-read.table (' clipboard ') #连接数据库library (RODBC) channel< -odbcconnect (' MySQL ', Uid=user,pwd=password) SqlTables (channel) Data<-sqlfetch (channel, "Customers") sqlquery ( Channel, ' SELECT * from Orders ') #读excel文档excelcha <-odbcconnectexcel (' C:/iris.xls ', Readonly=false) sqlTables ( Excelcha) Data<-sqlfetch (Excelcha, ' Sheet1 ') Data$new<-with (data.sqpal_length/sepal_width) Sqlsave (Excel, Data,tablename= ' Sheet3 ') #web数据抓取library (XML) url<-' www.google.com/adplanner/static/top1000 ' tables<- Readhtmltable (Url,stringasfactors=false,HEADER=F) data<-tables[[2] 


R Language Beginner Course (4)-Data summary Plyr package http://cos.name/videos/r101-plyr/

Data (tips,package= ' reshape2 ') library (PLYR) head (TIPS) aggregate (X=tips$tip,          by=list (tip$sex),          Fun=mean) Ddply (data=tips,      variables= ' sex ',      fun=function (x) {mean (X$tip)}) Ratio_fun <-function (x) {  sum (x$ Tip/sum (X$total_bill))}ddply (tips,. ( Sex), Ratio_fun) X<-1:10each (Min,max) (x) colwise (mean,is.numeric) (IRIS)


Basic R Language Course (5)-Regression analysis http://cos.name/videos/r101-regression/


R Language Learning Resources

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.