R语言_seq()函数用法

Python015

R语言_seq()函数用法,第1张

Sequence Generation:

生成规律的序列。seq是一个带有默认方法的标准通用。seq.int是一种原始的东西,它可以快得多,但也有一些限制。seq_along和seq_len是两个常见情况的参数。

使用方法:

参数说明:

from :生成向量的起点。

to :生成向量的终点。

by :序列的增量,默认步长为1(可修改)。

length.out :这个序列的输出长度。

对于seq和seq.int来说,如果分数的话,将会被四舍五入。

参考1: R语言中seq函数的用法

参考2:

在一个文档中定位到第一个空行,读取其后的所有文本  get.msg <- function(path)  {      con <- file(path, open = "rt", encoding = "latin1")        text <- readLines(con)      # The message always begins after the first full line break    msg <-... 文档定位第空行读取其所文本

get.msg <- function(path)

{

con <- file(path, open = "rt", encoding = "latin1")

text <- readLines(con)

# The message always begins after the first full line break

msg <- text[seq(which(text == "")[1]+1, length(text), 1)]

close(con)

return(paste(msg, collapse = "\n"))

}

报错:

Error in seq.default(which(text == "")[1]+1, length(text), 1) :

'from' cannot be NA, NaN or infinite 展开 示例文档:

From [email protected]  Thu Aug 22 13:17:22 2002

Return-Path: [email protected]>

Delivered-To: [email protected]

Received: from localhost (localhost [127.0.0.1])

by phobos.labs.spamassassin.taint.org (Postfix) with ESMTP id 136B943C32

for <zzzz@localhost>Thu, 22 Aug 2002 08:17:21 -0400 (EDT)

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<HTML><HEAD>

<META content=3D"text/htmlcharset=3Dwindows-1252" http-equiv=3DContent-T=

ype>