我有两个角色列表,第一个是A
> mode(A)
[1] "character"
> length(A)
[1] 300
> dim(A)
[1] 150 2
A就是这样的
> head(A)
[,1] [,2]
[1,] "000001" "601166"
[2,] "000027" "600582"
[3,] "000027" "600783"
[4,] "000027" "601088"
[5,] "000166" "000728"
[6,] "000333" "600519"
第二个列表是B,其中包含1000个元素
> length(B)
[1] 1000
> dim(B)
NULL
B的每个元素也具有以下特征
> mode(B[[1]])
[1] "character"
> length(B[[1]])
[1] 300
> dim(B[[1]])
[1] 150 2
B[[1]]
是
> head(B[[1]])
[,1] [,2]
[1,] "000001" "601818"
[2,] "000027" "600362"
[3,] "000027" "600827"
[4,] "000166" "601099"
[5,] "000333" "002304"
[6,] "000333" "601318"
我想计算一对A行的频率,例如
"000001" "601166"
在<{1}}的每个元素中,例如
B
我尝试了这段代码,但无法获得结果
B[[1]]
答案 0 :(得分:0)
我找到了解决方案,我只需要在代码中添加stringsAsFactors = FALSE
。
正确的代码是
M<-list()
for (i in 1:1000) {M[[i]]<-match(as.data.frame(t(A), stringsAsFactors = FALSE),as.data.frame(t(B[[i]]), stringsAsFactors = FALSE), nomatch=0)}
任何其他改善它的建议将不胜感激。