(1)函数:example,c,cbind,seq,rep,
(1)函数:example,c,cbind,seq,rep,
索引:提取数据,x[c(1,3,4,5)];删除数据[-2,-5,-7],names(x)<-c(‘one’,‘two’)
www.rstudio.com
桌面版本
选操作系统
优势:
脚本编辑
控制台:交互式命令
工作空间:变量,历史命令
文件系统
rstudio有代码提示
rattle,图形化操作界面
R区分大小写
1+1
2+2
在脚本区run
sin(30)
sqrt(12)
帮助系统
ploth绘图函数
help(plot)
example("plot")直接示例
工作空间
getwd() setwd()
文件操作,完整路径
setwd('c/user/zhang')
R包
library
函数.lib
包的安装
install.packages('arules')
安装过程中需要联网。
tools options cran mirror选中国清华大学镜像
调用library('arules')
使用时先加载detach
更新包
installed.package()
已经安装好的包
.library()
矩阵:a<-matrix(w,nrow,ncol),as.vector(x)
数组:array(x,dim=c(2,5,3)),dim(x),colsums
求和sum(y*2*pi/n)
因子型数据:factor(x),iris,鸢尾花,iris[,5],class(iris[,5]),chr<-c("R","Python","R","Rudy","Lisp"),‘R’),class(chr),(f<-factor(chr)),class(f),storage.mode(f),as.numeric(f),levels(f)
paste(x1,x2,sep=‘,’),strsplit(x,‘年’),list
my.list[[3]][3],my.list$id
iris[101:150,],iris[iris$Species=="virginica",];iris[iris$Species=="versicolor",c(1,2,3,4)];iris[iris$Sepal.Width>4,c(1,2,3,4)]
iris[iris$Sepal.Width>=4&iris$Sepal.Width<4.5,],attach(x),detach(x);iris[Sepal.Width>=4&Sepal.Width<4.5,];Tab<-data.frame(姓名=c('李伟','李佳玉','郑重'),成绩=c("60",'80','70'),性别=c('男','男','女'));b<-as.matrix(Tab); (as.data.frame(b))
paste(x1,x2,sep='');paste0(x1,x2),strsplit(x,""),substr(0,chartr(),gsub()
自定义函数:Calc<-function(x,y,z){z=x*x+y/2+z*z*z
return(z)};a<-"www.tipdm.com.html"
pa<-function(x,y){
b<-strsplit(x,'\\.')
n<-length(b[[1]])-1
return(b[[1]][n]==y)
安装数据包:learningr
deer_file<-system.file("extdatd")
getwd()
setwd("C:/Users/git/Documents/R/win-library/3.4/learningr")
deer_data<-read.table('./extdata/RedDeerEndocranialVolume.dlm',header=TRUE,fill=TRUE)
Theme<-system.file("extdata",
"Shakespeare.s.The.Tempest..from.Project.Gutenberg.pg2235.txt",
package = "learningr"
)
Themeread<-readLines(Theme)
rm(list=ls())
加载函数:attach;detach,去载:detach()
iris
mydata<-iris[,1:2]
attach(mydata)
(mydata$square<- Sepal.Length*Sepal.Width)
mydata1<- transform(mydata,square=Sepal.Length*Sepal.Width)
创建新属性:within(x,{ })
is.na,complete.cases()
基本函数:head(),tail(),前后6个数据显示
sum(),max(),min(),whic.max(),range(),length(),mean(),median(),quantile()
高级函数:round()取整,rnorm(),ceiling(),floor()
sample()随机抽样函数,sort(),order(),scale(),table()
数据粘贴函数:paste(),paste0()
函数merge()