错误...要替换的项目数不是替换长度的倍数
S = 0.001 # slope
h = 0.7 # m depth of flow
v = 0.000001 # m^2/s dynamic viscosity of water
g = 9.8 # m/s^2 gravitational acceleration
velocity <- matrix(0, ncol = 2, nrow = 14)
velocity[1,2] <- 0.05
velocity[2,2] <- 0.1
velocity[3,2] <- 0.15
velocity[4,2] <- 0.2
velocity[5,2] <- 0.25
velocity[6,2] <- 0.3
velocity[7,2] <- 0.35
velocity[8,2] <- 0.4
velocity[9,2] <- 0.45
velocity[10,2] <- 0.5
velocity[11,2] <- 0.55
velocity[12,2] <- 0.6
velocity[13,2] <- 0.65
velocity[14,2] <- 0.7
for(i in 1:14){
velocity[i,] <- (sqrt(g*h*S)/k) * log(velocity[,i]/z0)
}
print(velocity)
我不确定我哪里错了。我有一个 14 行矩阵,并尝试使用第二列来计算包含方程的第一列。将循环更改为 for(i in 1:n)
会出现 NA 错误
S = 0.001 # slope
h = 0.7 # m depth of flow
v = 0.000001 # m^2/s dynamic viscosity of water
g = 9.8 # m/s^2 gravitational acceleration
velocity <- matrix(0, ncol = 2, nrow = 14)
velocity[1,2] <- 0.05
velocity[2,2] <- 0.1
velocity[3,2] <- 0.15
velocity[4,2] <- 0.2
velocity[5,2] <- 0.25
velocity[6,2] <- 0.3
velocity[7,2] <- 0.35
velocity[8,2] <- 0.4
velocity[9,2] <- 0.45
velocity[10,2] <- 0.5
velocity[11,2] <- 0.55
velocity[12,2] <- 0.6
velocity[13,2] <- 0.65
velocity[14,2] <- 0.7
for(i in 1:14){
velocity[i,] <- (sqrt(g*h*S)/k) * log(velocity[,i]/z0)
}
print(velocity)
I'm not sure where I'm going wrong here. I have a matrix with 14 rows and am trying to use the 2nd column to calculate the first column with the included equation. Changing the loop to for(i in 1:n)
gives a NA error
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果你想通过 col2 获取 col1 的值,可以试试这个:
没有循环,你也可以尝试这个:
If you want to get values for col1 by col2, what about trying this:
Without loops, you can also try this: