比较两列,如果R相等,则用第三列替换?

时间:2018-07-27 14:17:51

标签: r match equality

dat包含col1:

  col1 
WBA02352
WBA01432
WBA89737
WBA07547

datText包含2列:

  col2         col3 
WBA00011   WBA-00:01:02:02
WBA12453   WBA-00:12:45:03
WBA01432   WBA-01:43:02
WBA89737   WBA-08:09:37
WBA89538   WBA-08:09:50:38
WBA95784   WBA-09:57:84
WBA07547   WBA-07:54:07

我对R还是陌生的,似乎无法理解循环。我想先检查col1中的哪些行等于col2,然后用相应的col3值创建一个新列。基本上使用datText(col2和col3)作为替换col1中值的参考。

以下是框架:

dat <- data.frame(col1)
col1 <- c("WBA02352", "WBA01432" , "WBA89737", "WBA07547")

datText <- data.frame(col2, col3)
col2 <- c("WBA00011", "WBA12453", "WBA01432", "WBA89737", "WBA89538", "WBA95784", "WBA07547")
col3 <- c("WBA-00:01:02:02", "WBA-00:12:45:03", "WBA-01:43:02", "WBA-08:09:37", "WBA-08:09:50:38", "WBA-09:57:84", "WBA-07:54:07")

0 个答案:

没有答案