structure(list(V1 = structure(c(9L, 1L, 2L, 3L, 4L, 5L, 6L, 7L,
8L), .Label = c("1", "2", "3", "4", "5", "6", "7", "8", "n"), class = "factor"),
V2 = structure(c(8L, 2L, 6L, 5L, 5L, 7L, 3L, 4L, 1L), .Label = c("0.02750910",
"0.02813027", "0.03230100", "0.03336587", "0.03487443", "0.03505191",
"0.03531813", "Prior_l"), class = "factor")), row.names = c(NA,
9L), class = "data.frame")
structure(list(V1 = structure(c(5L, 1L, 1L, 2L, 3L, 4L, 3L), .Label = c("1",
"2", "3", "5", "w"), class = "factor"), V2 = structure(c(7L,
3L, 4L, 5L, 1L, 2L, 6L), .Label = c("30", "35", "46", "67", "68",
"90", "tw_n"), class = "factor"), V3 = structure(c(5L, 2L, 3L,
4L, 1L, 2L, 4L), .Label = c("1", "2", "3", "8", "w_n"), class = "factor"),
V4 = structure(c(5L, 1L, 2L, 1L, 4L, 3L, 4L), .Label = c("1",
"2", "3", "4", "d"), class = "factor")), row.names = c(NA,
7L), class = "data.frame")
for (i in 1:8){
for (j in 1:10){
if df1$n == i
print((df1[i,2]))
print(sum(log(df$w_n/df$tw_n)))
print(max(log(df1[i,2])+sum(log(df$w_n/df$tw_n))))
test_case = max(log(df1[i,2])+sum(log(df$w_n/df$tw_n)))
print(i)
print df$d
i+1
j+1
}
}
我无法遍历程序并返回值,而不是单独打印。
df1
n Prior_l
1 0.02813027
2 0.03505191
3 0.03487443
4 0.03487443
5 0.03531813
6 0.03230100
7 0.03336587
8 0.02750910
df
w tw_n w_n d
1 46 2 1
1 67 3 2
2 68 8 1
3 30 1 4
5 35 2 3
3 90 8 4
我正在尝试使用公式中的值返回一个新的数据框:
max(log(Prior_l) + sum(all log P(w_n/tw_n)
例如,对于d = 1,我打算计算所有值,如图