如何创建以下 "if-else" 条件?
How can I create the following "if-else" condition?
我有这个数据框:
df <- structure(list(a = c(2, 5, 90, 77, 56, 65, 85, 75, 12, 24, 52, 32), b = c(45, 78, 98, 55, 63, 12, 23, 38, 75, 68, 99, 73), c = c(77, 85, 3, 22, 4, 69, 86, 39, 78, 36, 96, 11), d = c(52, 68, 4, 25,
79, 120, 97, 20, 7, 19, 37, 67), e = c(14, 73, 91, 87, 94, 38, 1, 685, 47, 102, 666, 74)), class = "data.frame", row.names = c(NA, -12L))
和这个脚本:
sqmat <- structure(c(12, 68, 1, 31, 5, 7, 25, 17, 1, 25, 17, 1, 31, 5,
7), .Dim = c(3L, 5L))
sqmat_2 <- structure(c(52, 4, 1, 31, 26, 22, 52, 4, 1, 23, 55, 12, 31, 26,
22), .Dim = c(3L, 5L))
我需要一个“if-else”条件:
如果 sqmat_2 (52) 中的输出 row=1, col=1 > 然后两次输出 row=1, col=1 in sqmat (2 x 12) => 给我“O” .
否则(如果 52 <= 2 x 12)给我“C”。
两个矩阵sqmat和sqmat_2逐点计算;并将结果显示在矩阵中。
我能怎么做?
谢谢你帮助我!
你是这个意思吗?
ifelse(sqmat_2 > (2*sqmat), "O", "C")
# [,1] [,2] [,3] [,4] [,5]
# [1,] "O" "C" "O" "C" "C"
# [2,] "C" "O" "C" "O" "O"
# [3,] "C" "O" "C" "O" "O"
我有这个数据框:
df <- structure(list(a = c(2, 5, 90, 77, 56, 65, 85, 75, 12, 24, 52, 32), b = c(45, 78, 98, 55, 63, 12, 23, 38, 75, 68, 99, 73), c = c(77, 85, 3, 22, 4, 69, 86, 39, 78, 36, 96, 11), d = c(52, 68, 4, 25,
79, 120, 97, 20, 7, 19, 37, 67), e = c(14, 73, 91, 87, 94, 38, 1, 685, 47, 102, 666, 74)), class = "data.frame", row.names = c(NA, -12L))
和这个脚本:
sqmat <- structure(c(12, 68, 1, 31, 5, 7, 25, 17, 1, 25, 17, 1, 31, 5,
7), .Dim = c(3L, 5L))
sqmat_2 <- structure(c(52, 4, 1, 31, 26, 22, 52, 4, 1, 23, 55, 12, 31, 26,
22), .Dim = c(3L, 5L))
我需要一个“if-else”条件:
如果 sqmat_2 (52) 中的输出 row=1, col=1 > 然后两次输出 row=1, col=1 in sqmat (2 x 12) => 给我“O” . 否则(如果 52 <= 2 x 12)给我“C”。
两个矩阵sqmat和sqmat_2逐点计算;并将结果显示在矩阵中。 我能怎么做? 谢谢你帮助我!
你是这个意思吗?
ifelse(sqmat_2 > (2*sqmat), "O", "C")
# [,1] [,2] [,3] [,4] [,5]
# [1,] "O" "C" "O" "C" "C"
# [2,] "C" "O" "C" "O" "O"
# [3,] "C" "O" "C" "O" "O"