根据名称使全局环境中对象的数据框与r中的值匹配

时间:2019-09-11 07:35:42

标签: r dataframe global

我想从全局环境中选择名称与“ best_dataframe”对象值匹配的数据框,然后从中创建一个新的数据框。请注意,“ best_dataframe”对象是从“ dataframe_values”列表中获得的,这些列表的顺序是从高到低。

这是一些示例代码:

dataframe_A <- data.frame(sample = c("OP2645ii_d","OP5048___g","OP5046___e","OP5048___g","OP2413iiia","OP5048___g","OP5043___b","OP5048___g","OP3088i__a","OP5048___g","OP5046___a","OP5048___g","OP5048___b","OP5048___g","OP5043___a","OP5048___g","OP2645ii_d","OP5048___f","OP2645ii_d","OP5044___c","OP2413iiib","OP5048___g","OP5046___c","OP5048___g","OP5046___d","OP5046___e","OP5048___e","OP5048___g","OP5046___e","OP5048___c","OP2413iiia","OP5046___e","OP2645ii_b","OP2645ii_d","OP2645ii_a","OP5046___e","OP5046___e","OP5048___d","OP5046___e","OP5048___e","OP2413iiia","OP5048___f","OP5044___c","OP5046___e","OP2413iiia","OP2645ii_c","OP5046___e","OP5047___b","OP2645ii_a","OP2645ii_d","OP5046___c","OP5046___e","OP5046___d","OP5048___g","OP2645ii_e","OP5048___g","OP2645ii_c","OP5046___d","OP5048___c","OP5048___g","OP2645ii_c","OP5048___c","OP2645ii_c","OP5048___e","OP2645ii_c","OP5048___g","OP5046___e","OP5048___f","OP2645ii_d","OP5046___d","OP2645ii_c","OP5046___c","OP2645ii_d","OP5048___d","OP5043___b","OP5048___f","OP5046___c","OP5048___f","OP2645ii_d","OP5048___c","OP2413iiib","OP5046___e","OP2413iiib","OP5048___f","OP5044___a","OP5048___g","OP5043___a","OP5048___f","OP3088i__a","OP5048___f","OP5048___e","OP5048___f","OP5044___c","OP5048___b","OP2645ii_d","OP5047___b","OP2413iiia","OP2645ii_b","OP5046___a","OP5048___f","OP5043___b","OP5044___c","OP2645ii_c","OP5048___d","OP5047___b","OP5048___g","OP5048___b","OP5048___f","OP2413iiia","OP5044___c","OP2645ii_b","OP5046___e","OP2645ii_c","OP5047___b","OP5044___c","OP5046___a","OP2413iiib","OP2645ii_c","OP2645ii_e","OP5046___e","OP5048___d","OP5048___g","OP5046___d","OP5048___b","OP2645ii_a","OP2645ii_c","OP3088i__a","OP5044___c"),
                                          gr = c("gr3","gr2","gr5","gr2","gr1","gr2","gr1","gr2","gr1","gr2","gr5","gr2","gr5","gr2","gr3","gr2","gr3","gr2","gr3","gr2","gr4","gr2","gr1","gr2","gr4","gr5","gr1","gr2","gr5","gr4","gr1","gr5","gr2","gr3","gr1","gr5","gr5","gr4","gr5","gr1","gr1","gr2","gr2","gr5","gr1","gr5","gr5","gr4","gr1","gr3","gr1","gr5","gr4","gr2","gr1","gr2","gr5","gr4","gr4","gr2","gr5","gr4","gr5","gr1","gr5","gr2","gr5","gr2","gr3","gr4","gr5","gr1","gr3","gr4","gr1","gr2","gr1","gr2","gr3","gr4","gr4","gr5","gr4","gr2","gr3","gr2","gr3","gr2","gr1","gr2","gr1","gr2","gr2","gr5","gr3","gr4","gr1","gr2","gr5","gr2","gr1","gr2","gr5","gr4","gr4","gr2","gr5","gr2","gr1","gr2","gr2","gr5","gr5","gr4","gr2","gr5","gr4","gr5","gr1","gr5","gr4","gr2","gr4","gr5","gr1","gr5","gr1","gr2"))

dataframe_B <- data.frame(sample = c("OP2645ii_d","OP5048___g","OP5046___e","OP5048___g","OP2413iiia","OP5048___g","OP5043___b","OP5048___g","OP3088i__a","OP5048___g","OP5046___a","OP5048___g","OP5048___b","OP5048___g","OP5043___a","OP5048___g","OP2645ii_d","OP5048___f","OP2645ii_d","OP5044___c","OP2413iiib","OP5048___g","OP5046___c","OP5048___g","OP5046___d","OP5046___e","OP5048___e","OP5048___g","OP5046___e","OP5048___c","OP2413iiia","OP5046___e","OP2645ii_b","OP2645ii_d","OP2645ii_a","OP5046___e","OP5046___e","OP5048___d","OP5046___e","OP5048___e","OP2413iiia","OP5048___f","OP5044___c","OP5046___e","OP2413iiia","OP2645ii_c","OP5046___e","OP5047___b","OP2645ii_a","OP2645ii_d","OP5046___c","OP5046___e","OP5046___d","OP5048___g","OP2645ii_e","OP5048___g","OP2645ii_c","OP5046___d","OP5048___c","OP5048___g","OP2645ii_c","OP5048___c","OP2645ii_c","OP5048___e","OP2645ii_c","OP5048___g","OP5046___e","OP5048___f","OP2645ii_d","OP5046___d","OP2645ii_c","OP5046___c","OP2645ii_d","OP5048___d","OP5043___b","OP5048___f","OP5046___c","OP5048___f","OP2645ii_d","OP5048___c","OP2413iiib","OP5046___e","OP2413iiib","OP5048___f","OP5044___a","OP5048___g","OP5043___a","OP5048___f","OP3088i__a","OP5048___f","OP5048___e","OP5048___f","OP5044___c","OP5048___b","OP2645ii_d","OP5047___b","OP2413iiia","OP2645ii_b","OP5046___a","OP5048___f","OP5043___b","OP5044___c","OP2645ii_c","OP5048___d","OP5047___b","OP5048___g","OP5048___b","OP5048___f","OP2413iiia","OP5044___c","OP2645ii_b","OP5046___e","OP2645ii_c","OP5047___b","OP5044___c","OP5046___a","OP2413iiib","OP2645ii_c","OP2645ii_e","OP5046___e","OP5048___d","OP5048___g","OP5046___d","OP5048___b","OP2645ii_a","OP2645ii_c","OP3088i__a","OP5044___c"),
                          gr = c("gr5","gr2","gr3","gr2","gr1","gr2","gr1","gr2","gr1","gr4","gr5","gr2","gr5","gr1","gr3","gr3","gr3","gr2","gr3","gr2","gr4","gr2","gr1","gr2","gr4","gr5","gr1","gr2","gr5","gr4","gr1","gr5","gr2","gr3","gr1","gr5","gr5","gr4","gr5","gr1","gr1","gr2","gr2","gr5","gr1","gr5","gr5","gr4","gr1","gr3","gr1","gr5","gr4","gr2","gr1","gr2","gr5","gr4","gr4","gr2","gr5","gr4","gr5","gr1","gr5","gr2","gr5","gr2","gr3","gr4","gr5","gr1","gr3","gr4","gr1","gr2","gr1","gr2","gr3","gr4","gr4","gr5","gr4","gr2","gr3","gr2","gr3","gr2","gr1","gr2","gr1","gr2","gr2","gr5","gr3","gr4","gr1","gr2","gr5","gr2","gr1","gr2","gr5","gr4","gr4","gr2","gr5","gr2","gr1","gr2","gr2","gr5","gr5","gr4","gr2","gr5","gr4","gr5","gr1","gr5","gr4","gr2","gr4","gr5","gr1","gr5","gr1","gr2"))

dataframe_C <- data.frame(sample = c("OP2645ii_d","OP5048___g","OP5046___e","OP5048___g","OP2413iiia","OP5048___g","OP5043___b","OP5048___g","OP3088i__a","OP5048___g","OP5046___a","OP5048___g","OP5048___b","OP5048___g","OP5043___a","OP5048___g","OP2645ii_d","OP5048___f","OP2645ii_d","OP5044___c","OP2413iiib","OP5048___g","OP5046___c","OP5048___g","OP5046___d","OP5046___e","OP5048___e","OP5048___g","OP5046___e","OP5048___c","OP2413iiia","OP5046___e","OP2645ii_b","OP2645ii_d","OP2645ii_a","OP5046___e","OP5046___e","OP5048___d","OP5046___e","OP5048___e","OP2413iiia","OP5048___f","OP5044___c","OP5046___e","OP2413iiia","OP2645ii_c","OP5046___e","OP5047___b","OP2645ii_a","OP2645ii_d","OP5046___c","OP5046___e","OP5046___d","OP5048___g","OP2645ii_e","OP5048___g","OP2645ii_c","OP5046___d","OP5048___c","OP5048___g","OP2645ii_c","OP5048___c","OP2645ii_c","OP5048___e","OP2645ii_c","OP5048___g","OP5046___e","OP5048___f","OP2645ii_d","OP5046___d","OP2645ii_c","OP5046___c","OP2645ii_d","OP5048___d","OP5043___b","OP5048___f","OP5046___c","OP5048___f","OP2645ii_d","OP5048___c","OP2413iiib","OP5046___e","OP2413iiib","OP5048___f","OP5044___a","OP5048___g","OP5043___a","OP5048___f","OP3088i__a","OP5048___f","OP5048___e","OP5048___f","OP5044___c","OP5048___b","OP2645ii_d","OP5047___b","OP2413iiia","OP2645ii_b","OP5046___a","OP5048___f","OP5043___b","OP5044___c","OP2645ii_c","OP5048___d","OP5047___b","OP5048___g","OP5048___b","OP5048___f","OP2413iiia","OP5044___c","OP2645ii_b","OP5046___e","OP2645ii_c","OP5047___b","OP5044___c","OP5046___a","OP2413iiib","OP2645ii_c","OP2645ii_e","OP5046___e","OP5048___d","OP5048___g","OP5046___d","OP5048___b","OP2645ii_a","OP2645ii_c","OP3088i__a","OP5044___c"),
                          gr = c("gr2","gr5","gr2","gr2","gr1","gr2","gr1","gr1","gr1","gr2","gr2","gr2","gr5","gr2","gr3","gr2","gr3","gr2","gr3","gr2","gr4","gr2","gr1","gr2","gr4","gr5","gr1","gr2","gr5","gr4","gr1","gr5","gr2","gr3","gr1","gr5","gr5","gr4","gr5","gr1","gr1","gr2","gr2","gr5","gr1","gr5","gr5","gr4","gr1","gr3","gr1","gr5","gr4","gr2","gr1","gr2","gr5","gr4","gr4","gr2","gr5","gr4","gr5","gr1","gr5","gr2","gr5","gr2","gr3","gr4","gr5","gr1","gr3","gr4","gr1","gr2","gr1","gr2","gr3","gr4","gr4","gr5","gr4","gr2","gr3","gr2","gr3","gr2","gr1","gr2","gr1","gr2","gr2","gr5","gr3","gr4","gr1","gr2","gr5","gr2","gr1","gr2","gr5","gr4","gr4","gr2","gr5","gr2","gr1","gr2","gr2","gr5","gr5","gr4","gr2","gr5","gr4","gr5","gr1","gr5","gr4","gr2","gr4","gr5","gr1","gr5","gr1","gr2"))


dataframe_D <- data.frame(sample = c("OP2645ii_d","OP5048___g","OP5046___e","OP5048___g","OP2413iiia","OP5048___g","OP5043___b","OP5048___g","OP3088i__a","OP5048___g","OP5046___a","OP5048___g","OP5048___b","OP5048___g","OP5043___a","OP5048___g","OP2645ii_d","OP5048___f","OP2645ii_d","OP5044___c","OP2413iiib","OP5048___g","OP5046___c","OP5048___g","OP5046___d","OP5046___e","OP5048___e","OP5048___g","OP5046___e","OP5048___c","OP2413iiia","OP5046___e","OP2645ii_b","OP2645ii_d","OP2645ii_a","OP5046___e","OP5046___e","OP5048___d","OP5046___e","OP5048___e","OP2413iiia","OP5048___f","OP5044___c","OP5046___e","OP2413iiia","OP2645ii_c","OP5046___e","OP5047___b","OP2645ii_a","OP2645ii_d","OP5046___c","OP5046___e","OP5046___d","OP5048___g","OP2645ii_e","OP5048___g","OP2645ii_c","OP5046___d","OP5048___c","OP5048___g","OP2645ii_c","OP5048___c","OP2645ii_c","OP5048___e","OP2645ii_c","OP5048___g","OP5046___e","OP5048___f","OP2645ii_d","OP5046___d","OP2645ii_c","OP5046___c","OP2645ii_d","OP5048___d","OP5043___b","OP5048___f","OP5046___c","OP5048___f","OP2645ii_d","OP5048___c","OP2413iiib","OP5046___e","OP2413iiib","OP5048___f","OP5044___a","OP5048___g","OP5043___a","OP5048___f","OP3088i__a","OP5048___f","OP5048___e","OP5048___f","OP5044___c","OP5048___b","OP2645ii_d","OP5047___b","OP2413iiia","OP2645ii_b","OP5046___a","OP5048___f","OP5043___b","OP5044___c","OP2645ii_c","OP5048___d","OP5047___b","OP5048___g","OP5048___b","OP5048___f","OP2413iiia","OP5044___c","OP2645ii_b","OP5046___e","OP2645ii_c","OP5047___b","OP5044___c","OP5046___a","OP2413iiib","OP2645ii_c","OP2645ii_e","OP5046___e","OP5048___d","OP5048___g","OP5046___d","OP5048___b","OP2645ii_a","OP2645ii_c","OP3088i__a","OP5044___c"),
                          gr = c("gr1","gr1","gr1","gr2","gr1","gr2","gr1","gr5","gr1","gr2","gr5","gr2","gr5","gr2","gr3","gr2","gr3","gr2","gr3","gr2","gr4","gr2","gr1","gr2","gr4","gr5","gr1","gr2","gr5","gr4","gr1","gr5","gr2","gr3","gr1","gr5","gr5","gr4","gr5","gr1","gr1","gr2","gr2","gr5","gr1","gr5","gr5","gr4","gr1","gr3","gr1","gr5","gr4","gr2","gr1","gr2","gr5","gr4","gr4","gr2","gr5","gr4","gr5","gr1","gr5","gr2","gr5","gr2","gr3","gr4","gr5","gr1","gr3","gr4","gr1","gr2","gr1","gr2","gr3","gr4","gr4","gr5","gr4","gr2","gr3","gr2","gr3","gr2","gr1","gr2","gr1","gr2","gr2","gr5","gr3","gr4","gr1","gr2","gr5","gr2","gr1","gr2","gr5","gr4","gr4","gr2","gr5","gr2","gr1","gr2","gr2","gr5","gr5","gr4","gr2","gr5","gr4","gr5","gr1","gr5","gr4","gr2","gr4","gr5","gr1","gr5","gr1","gr2"))


dataframe_values <- data.frame(name = c("dataframe_A", "dataframe_B", "dataframe_C", "dataframe_D"), value = c("14", "10", "11", "5"))

best_dataframe <- dataframe_values[1,1]

我想选择'dataframe_A'来基于名称与对象字符串'dataframe_A'匹配的对象'best_dataframe'来制作新的数据帧。

0 个答案:

没有答案