读取EXCEL中的某个SHEET
> library(xlsx)
载入需要的程辑包:rJava
载入需要的程辑包:xlsxjars
> degree=read.xlsx("Statistics.xlsx",sheetName = "degree")
也可以指定SHEET编号:
> degree=read.xlsx("Statistics.xlsx",sheetIndex = "5")
对于之前版本的EXCEL(.xls)等,需用gdata库
>library(gdata)
# Read first sheet
>data = read.xls("datafile.xls")
遇到问题:
下载“rJava”库后,调用时说
选择excel数据,再用(CTRL+C)复制。在R中键入命令:
mydata <- read.delim("clipboard")
行统计和列统计
> rowSums(data=="Yes")
[1] 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
> rowSums(data>=0)
[1] 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30
[25] 30 30 30 30 30
> colSums(data>=0)
X1 X2 X3 X4 X5 X6 X7 X8 X9 X10 X11 X12 X13 X14 X15 X16 X17 X18 X19
30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30 30
X20 X21 X22 X23 X24 X25 X26 X27 X28 X29 X30
30 30 30 30 30 30 30 30 30 30 30
> data.m=as.matrix(data)
> data.m