颖哥写基本命令

1.画网格

abline(h=seq(1,10,.5),col="blue")

abline(v=seq(1, 10, .5), lty=2, col="blue")  ###参考线垂直线



2.2Data structure


a <- c(1, 2, 5, 3, 6, -2, 4) ##vector

a[c(2,3, 4)]


rnames <- c("R1", "R2")   # matrix with rowname

cnames <- c("C1", "C2") 

mymatrix <- matrix(c(1,2,3,1,9,6), nrow=2, ncol=2, byrow=TRUE, dimnames=list(rnames, cnames))


dim1 <- c("A1", "A2")

dim2 <- c("B1", "B2", "B3")

dim3 <- c("C1", "C2", "C3", "C4")

z <- array(1:24, c(2, 3, 4), dimnames=list(dim1, dim2, dim3))  ## array 数组


patientID <- c(1, 2, 3, 4)

age <- c(25, 34, 28, 52)

diabetes <- c("Type1", "Type2", "Type1", "Type1")

status <- c("Poor", "Improved", "Excellent", "Poor")

patientdata <- data.frame(patientID,age, diabetes, status)   ## data.frame 数据框

table(patientdata$diabetes, patientdata$status)

patientdata <- data.frame(patientID, age, diabetes, status,row.names=patientID)



status <- c("Poor", "Improved", "Excellent", "Poor")

status <- factor(status, ordered=TRUE)                  ## facotr 因子(有序无序)

status <- factor(status, order=TRUE,levels=c("Poor", "Improved", "Excellent"))


g <- "My First List"

h <- c(25, 26, 18, 39)

j <- matrix(1:10, nrow=5)

k <- c("one", "two", "three")

mylist <- list(title=g, ages=h, j, k) ## list 列表,组合四种components: string, vector,matrix,character vector




##2.3 数据输入

## 1.直接在R上输入;  for small datasets

mydata <- data.frame(age=numeric(0), gender=character(0), weight=numeric(0))

mydata <- edit(mydata)  


## 2.data from a delimited text file

mydataframe <- read.table(file, header=TRUE or FALSE, sep="delimiter", row.names="name")

grades <- read.table("studentgrades.csv", header=TRUE, sep=",", row.names="STUDENTID")   #例子


##3. Importing data from Excel

data1<-read.csv("studentgrades.csv",sep=",",header=TRUE)  ##直接导入csv

library(RODBC)   ##use the RODBC package to access Excel files

channel <- odbcConnectExcel("studentgrades.xls")

mydataframe <- sqlFetch(channel, "mysheet")

odbcClose(channel)




## 第三章 graphs


dose <- c(20, 30, 40, 45, 60)

drugA <- c(16, 20, 27, 40, 60)

drugB <- c(15, 18, 25, 31, 40)

plot(dose, drugA, type="b")

par(pin=c(4,3), mai=c(1,.5, 1, .2)) ##图形尺寸如生成4英寸宽、3高、上下边界为1、左0.5、右0.2的图

plot(dose, d

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值