Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/70.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在R中复制Excel函数索引_R_Excel_Data.table_Match_Vlookup - Fatal编程技术网

在R中复制Excel函数索引

在R中复制Excel函数索引,r,excel,data.table,match,vlookup,R,Excel,Data.table,Match,Vlookup,我试图在R中复制Excel的“索引”功能,不幸的是,我无法调整此板上提供的任何解决方案来解决我的问题。 我的第一个表包含列索引和行索引,根据这些索引从第二个表中选择值: library(data.table) table1<-data.table(data.frame(RowIndex = c(1,2,4,3), ColumnIndex = c(2,3,1,1))) table2<-data.table(data.frame(columnAD = c("a","b","c","d")

我试图在R中复制Excel的“索引”功能,不幸的是,我无法调整此板上提供的任何解决方案来解决我的问题。 我的第一个表包含列索引和行索引,根据这些索引从第二个表中选择值:

library(data.table)
table1<-data.table(data.frame(RowIndex = c(1,2,4,3), ColumnIndex = c(2,3,1,1)))
table2<-data.table(data.frame(columnAD = c("a","b","c","d"), columnEH = c("e","f","g","h"), columnIL = c("i","j","k","l")))
table1$MatchedData<-c("e","j","d","c")
Excel中所需的输出被添加为“匹配数据”。到目前为止,我已经尝试了match或ifelse的不同组合,但都没有成功。 提前感谢您的帮助

一种方法是使用by=为表1的每一行子集表2:


请注意,[]仅在赋值后打印表1,引用:=。

使用基本R矩阵数字索引:

as.matrix(table2)[as.matrix(table1)]

这个问题是否包括使其可复制所需的所有数据?也许您可以设定从其他表生成MatchedData向量的规则或过程。我已经将表的维度缩小了很多,但是生成´´´´´´´MatchedData´´´´基本上归结为转换´´´=INDEXTable2$B$2:$D$5,A2,B2´´´´或´´´=索引数组,行数,[列数]´´´´到R。但直到现在,我还不能根据我的具体数据调整@Ian Campbell的解决方案,所以我可能忽略了一些东西。
as.matrix(table2)[as.matrix(table1)]