99999久久久久久亚洲,欧美人与禽猛交狂配,高清日韩av在线影院,一个人在线高清免费观看,啦啦啦在线视频免费观看www

熱線電話:13121318867

登錄
2019-03-07 閱讀量: 1571
R里怎么讀取指定的行和列

# 函數(shù)目標:

# 讀取文件中的指定行和指定列

# 不包括注釋行

read_part <- function(file, rows = 1, columns = -1, sep = "\t",

stringsAsFactors = FALSE,

header = FALSE,

check.names = FALSE,

comment.char = "#", ...){

dfl <- list()

if (grepl("gz$", file)){

con <- gzfile(file, open = "rb")

} else{

con <- file(file, open = "r")

}

i <- 0

j <- 1

repeat{

rec <- readLines(con, 1)

if (length(rec) == 0) break

i <- i + 1

# 當rows = -1時, 會讀取所有行

# 超過目標行時停止讀取

if (i > max(rows) & rows != -1) break

# 不考慮注釋行

if (grepl(comment.char, rec )) next

if ( ! i %in% rows & rows != -1) next

items <- strsplit(rec, split = sep, fixed = TRUE)[[1]]

if ( columns == -1){

select_cols <- items

} else{

select_cols <- items[columns]

}

#print(select_cols)

dfl[[j]] <- select_cols

j <- j + 1

}

close(con)

df <- do.call(rbind, dfl)

return(df)

}

30.0000
1
關注作者
收藏
評論(0)

發(fā)表評論

暫無數(shù)據(jù)
推薦帖子