r - In R, how can loop multiple variable at the same?
问题描述
I am wondering of how can I loop the multiple variables at the same time in R.
For example,
a = c(1, 2, 3)
b = c(4, 5, 6)
And then for loop, the below code didnt work.
for (i, j in a, b) {
print(i)
print(j)
}
In Python,
for i,j in zip(a,b):
print(i)
print(j)
it is possible. How can I do this in R?
解决方案
使用 R 是不可能的,在这种情况下,最好的解决方案是遍历一个数组的长度并在每个数组的位置打印值:
a = c(1, 2, 3)
b = c(4, 5, 6)
for(i in 1:length(a))
{
print(a[i])
print(b[i])
}
推荐阅读
- java - 更新 Android Gradle 插件会影响您的代码吗?
- python - Jupyter Lab 中未显示 Plotly 图表
- android - GraphRequest.newMeRequest 与 Profile.getCurrentProfile()
- mongodb - 需要查找以二进制形式存储在 mongodb 中的每个图像的大小(大于 100KB)
- xpath - Xpath 在某个类之后开始抓取并在下一个类之前停止
- reactjs - 在弹出窗口中打印 ag-grid - 反应
- opengl - 支持第三方应用程序的 OpenGL 屏幕捕获
- java - 重新验证并重新绘制 JScrollPane
- php - 语法错误,意外的 '$...' (T_VARIABLE) - 为什么?
- c++ - ffi-napi 如何接受包含 char 数组的结构作为返回类型?