创建字典并用R替换短语中的拉丁词

时间:2018-10-12 10:52:39

标签: r string dplyr

发布与此类似的信息 Create dictionary and replace by it latin words in R。 Moody_Mudskipper的解决方案很好,但是 让我们检查一下这句话

2049750 TESS чай солид     450mg

,依此类推... 确实我必须得到

2049750 ТЕСС чай солид     450mg

但是

output <- with(lapply(dict,as.character), new[match(tolower(input),old)])
output

我只得到NA后。 怎么了?

 NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA

_我的字典

dict <- structure(list(
  old = structure(c(2L, 1L), .Label = c("mag", "tess"),class = "factor"),
  new = structure(c(2L, 1L), .Label = c("маг", "тесс"), class = "factor")),
  .Names = c("old", "new"), class = "data.frame", row.names = c(NA, -2L))

输入

input<-("2049750 TESS чай солид     450mg")

所需的输出

2049750 ТЕСС чай солид     450mg

现在我可以输出了

1.Na
2.Na
...
35000 NA

1 个答案:

答案 0 :(得分:2)

您可以尝试以下方法:

        DataTable dt1 = new DataTable();
        dt1.Columns.Add("a");
        dt1.Columns.Add("b");

        for (int j = 0; j < 10; j++)
        {
            dt1.Rows.Add("a" + j.ToString(), "b" + j.ToString());
        }

        this.dataGridView1.DataSource = dt1;

        //I take a TextBox for example
        TextBox tx = new TextBox();

        //Add this TextBox into the DataGridView's control collection
        this.dataGridView1.Controls.Add(tx);

        //Add an extra row into the data source
        dt1.Rows.InsertAt(dt1.NewRow(), 0);

        //Make the first row frozen.
        this.dataGridView1.Rows[0].Frozen = true;

        //Resize the TextBox and put it over the first row
        Rectangle rect = this.dataGridView1.GetCellDisplayRectangle(0, 0, true);
        tx.Location = rect.Location;

        int w = 0;
        foreach (DataGridViewColumn c in this.dataGridView1.Columns)
        {
            w += c.Width;
        }

        tx.Width = w;
        tx.Height = this.dataGridView1.Rows[0].Height;
    }
}