Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一组包含 3 列的数据:索引列(没有名称)、颜色、种子颜色和发芽时间。
如何创建一个名为“order”的数值变量,其值为 1 到 22(数据集的数量)?
我不知道我是否正确,但最简单的方法是:
> order <- c(1:22) > order [1] 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
不,如果你运行:
class(order)
你会得到:
[1] "integer"
但是您可以轻松获取对象顺序的每个元素(尤其是在循环中)
for(i in 1:length(order)){ print(order[i]) }