Array in R

来源:互联网 发布:数据建模经典教程 pdf 编辑:程序博客网 时间:2024/05/18 03:01

Iterating an array

As in many other programming languages, you repeat an action for every entry of a vector through a for loop[1].

for(i in values){  ... do something ...}

seq_along creates a sequence from 1 up to the length of its input[2]:

pp <- c("Peter", "Piper", "picked", "a", "peck", "of", "pickled", "peppers")for(i in seq_along(pp)) print(pp[i])

[1] http://www.dummies.com/programming/r/how-to-loop-through-values-in-r/
[2] https://www.safaribooksonline.com/library/view/learning-r/9781449357160/ch04.html

原创粉丝点击