Dynamically adding values to dynamically created vectors
I just started learning to code in R. I have a requirement where I have to keep adding unknown number of values to different vectors (number of vectors is not known). So, I tried to implement this using -
clust_oo = c()
clust_oo[k] = c(clust_oo[k],init_dataset[k,1])
Without the [k]
, the above code works but since i don't know the number of vectors/lists i have to use [k]
as a differentiator. clust_oo[1]
could have values say, 1
, 23
, 45
, clust_oo[2]
could have other values 4
, 40
and clust_oo[3]
with values 44
, 67
, 455
, 885
. Where the values are added dynamically.
Is this the right way to proceed for this?
尝试:
clust_oo = c()
for(i in 1:3)
clust_oo[length(clust_oo)+1] = i
clust_oo
[1] 1 2 3
链接地址: http://www.djcxy.com/p/24872.html
上一篇: 将分数转换为R向量中的小数
下一篇: 动态添加值到动态创建的向量