R语言 如何读取excel里的指定行列
关键词:r语言 读取excel、r语言读取excel数据、r语言读取excel一列
语言里可以实现将excel文件里的指定行列直接读取到变量中吗?不通过读取后变量筛选,
解答:
导入Exel文件我喜欢用“xlsx”package;
用read.xslx() 读取文件
read.xslx()里面的colIndex 和 rowIndex 两个属性来定义列数和行数
假设取一个文件的18-23行,7-15列
install.packages(“xlsx”)
library(xlsx)
fileUrl <- “testdata.xlsx”
srow <- 18:23
scol <- 7:15
dat <- read.xslx(fileUrl, sheetIndex=1, colIndex=scol, rowIndex=srow)
## sheetIndex 指的是文件中第一张工作表
R语言的读取数据文件查看内容
关键词:r语言读取csv文件 r语言读取txt文件
解答:
读取数据文件查看内容
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
# Goal: To read in a simple data file, and look around it's contents.# Suppose you have a file "x.data" which looks like this:# 1997,3.1,4# 1998,7.2,19# 1999,1.7,2# 2000,1.1,13# To read it in --A <- read.table("x.data", sep=",", col.names=c("year", "my1", "my2"))nrow(A) # Count the rows in Asummary(A$year) # The column "year" in data frame A # is accessed as A$yearA$newcol <- A$my1 + A$my2 # Makes a new column in Anewvar <- A$my1 - A$my2 # Makes a new R object "newvar"A$my1 <- NULL # Removes the column "my1"# You might find these useful, to "look around" a dataset --str(A)summary(A)library(Hmisc) # This requires that you've installed the Hmisc packagecontents(A)describe(A) |
转载请注明:数据分析 » R语言 如何读取excel里的指定行列_R语言读取数据文件
