我正在try 将一个数组列表乘以一个数据帧列表,但结果并不像我想象的那样.
数组是维度为5x2的2的列表,数据帧是维度为5x2的2的列表.以下是数据
mat1 <- list(emote = structure(c(32.159, -3.608, -4.763,
5.394, 8.581, 71.258, 0.427, -0.323, 10.427, 21.967),
dim = c(5L, 2L),
dimnames = list(c("(Icpt)", "pl", "ed", "fin", "hp"), c("A", "B"))),
sceng = structure(c(105.992, -0.011, 5.847, -10.575,
-24.148, 229.327, 7.864, 18.654, -3.56, -8.6),
dim = c(5L, 2L),
dimnames = list(c("(Icpt)", "pl", "ed", "fin", "hp"), c("A", "B"))))
df1 <- list(emote = structure(list(Var1 = structure(1:5, levels = c("(Icpt)", "pl", "ed", "fin", "hp"),
class = "factor"), value = c(0.079, 0.013, 0.005, 0.017, 0.013)),
row.names = c(NA, -5L), class = "data.frame"),
sceng = structure(list(Var1 = structure(1:5, levels = c("(Icpt)", "pl", "ed", "fin", "hp"),
class = "factor"), value = c(0.136, 0.027, 0.009, 0.032, 0.021)),
row.names = c(NA, -5L), class = "data.frame"))
我想做的是将数组emote
的列A和B中的值乘以dataframe语句的列value
中的值,并将数组sceng
中的列A和B的值乘以dataframe sceng的列value
中的值.
在理想的情况下,我认为像lapply(mat1, '*', df1)
这样的脚本应该可以工作.我还用了
mapply(function(x, y) if(all(is.numeric(x), is.numeric(y))) x * y else x, mat1, df1)
排除字符值,但结果是错误的.最终数据帧/数组
我正在寻找将如下所示的东西:
$emote
A B
(Icpt) 2.5406 5.6294
pl -0.0469 0.0056
ed -0.0238 -0.0016
fin 0.0917 0.1773
hp 0.1116 0.2856
$sceng
A B
(Icpt) 14.4149 31.1885
pl -0.0003 0.2123
ed 0.0526 0.1679
fin -0.3384 -0.1139
hp -0.5071 -0.1806