用另一个数据框替换一个数据框中的两个单元格

时间:2019-08-02 05:01:46

标签: r

抱歉,我想这是以前被问过的,但是我很难找到它。也许我对它的描述很差。我需要覆盖数据框中的一些值。

我有以下输入内容:

input = structure(list(a.Date = c("19-Sep-18", "19-Sep-18", "18-Mar-19", 
"18-Mar-19", "7-Dec-18", "2-Aug-18", "15-Aug-18", "8-Mar-19", 
"21-Dec-18", "29-Jul-19"), Name = c("Frank", "Gene", "Simon", 
"Bob", "Bill", "Tony", "Scott", "Angela", "Millie", "Fred"), 
    a.Result = c(381, 84, 851, 550, 87, 922, 59, 912, 603, 113
    ), Rank = c(1L, 2L, 4L, 3L, 5L, 8L, 6L, 7L, 9L, 10L), b.Result = c(891, 
    525, 795, 697, 351, 724, 341, 615, 395, 229), b.Date = c("19-Sep-18", 
    "19-Sep-18", "18-Mar-19", "18-Mar-19", "7-Dec-18", "2-Aug-18", 
    "15-Aug-18", "8-Mar-19", "21-Dec-18", "29-Jul-19"), c.Result = c(931, 
    462, 323, 936, 996, 26, 93, 820, 468, 265), c.Date = c("19-Sep-18", 
    "19-Sep-18", "18-Mar-19", "18-Mar-19", "7-Dec-18", "2-Aug-18", 
    "15-Aug-18", "8-Mar-19", "21-Dec-18", "29-Jul-19")), class = "data.frame", row.names = c(NA, 
-10L))

我有这些替换值:

replace = structure(list(X = structure(17786, class = "Date"), Bill = -2081.568737826), row.names = 1L, class = "data.frame")

我正在尝试获得以下输出:

output = structure(list(a.Date = c("19-Sep-18", "19-Sep-18", "18-Mar-19", 
"18-Mar-19", "7-Dec-18", "2-Aug-18", "15-Aug-18", "8-Mar-19", 
"21-Dec-18", "29-Jul-19"), Name = c("Frank", "Gene", "Simon", 
"Bob", "Bill", "Tony", "Scott", "Angela", "Millie", "Fred"), 
    a.Result = c(381, 84, 851, 550, 87, 922, 59, 912, 603, 113
    ), Rank = c(1L, 2L, 4L, 3L, 5L, 8L, 6L, 7L, 9L, 10L), b.Result = c(891, 
    525, 795, 697, 351, 724, 341, 615, 395, 229), b.Date = c("19-Sep-18", 
    "19-Sep-18", "18-Mar-19", "18-Mar-19", "7-Dec-18", "2-Aug-18", 
    "15-Aug-18", "8-Mar-19", "21-Dec-18", "29-Jul-19"), c.Result = c("931.00", 
    "462.00", "323.00", "936.00", "-2,081.57", "26.00", "93.00", 
    "820.00", "468.00", "265.00"), c.Date = c("19-Sep-18", "19-Sep-18", 
    "18-Mar-19", "18-Mar-19", "12-Sep-18", "2-Aug-18", "15-Aug-18", 
    "8-Mar-19", "21-Dec-18", "29-Jul-19")), class = "data.frame", row.names = c(NA, 
-10L))

我用“替换”数据框替换了几个值。

我尝试使用match函数来定位要替换的单元格,但是我无法使其正常工作。谁能指出我正确的方向?

1 个答案:

答案 0 :(得分:2)

我们可以用<input type="hidden" name="_token" value="{{ csrf_token() }}"> match replace中的列名。在input$Name中更改日期的format,并更新replace数据框。

input