首页 > 代码库 > R语言常用基础知识

R语言常用基础知识

seq(from = 1, to = 1, by = ((to - from)/(length.out - 1)),
    length.out = NULL, along.with = NULL, ...)

举例----------Examples----------
seq(0, 1, length.out=11)
seq(stats::rnorm(20)) # 
seq(1, 9, by = 2)     # 
seq(1, 9, by = pi)    # 
seq(1, 6, by = 3)
seq(1.575, 5.125, by=0.05)
seq(17) # same as 1:17, or even better seq_len(17)

 

Loops

The most commonly used loop structures in R are for, while and apply loops. Less common are repeat loops. The break function is used to break out of loops, and next halts the processing of the current iteration and advances the looping index.

for(variable in sequence) {
    statements
}

while(condition) statements
apply(X, MARGIN, FUN, ARGs)