R语言模糊匹配出真实值

rm(list = ls())

library(tidyr)
library(dplyr)
library(lubridate)
library(rJava)
library(xlsxjars)
library(xlsx)
library(data.table)
library(readr)
library(readxl)


setwd('G:\\R\\data\\0423')


dir()


data1 <- read_excel('data1.xlsx')


data2 <- read_excel('data2.xlsx')


data1$bz <- 0


for (i in 1:nrow(data2)) {
  
  if (sum(data1$bz) == 0){
    
    data1$bz <-  grepl(pattern = data2$gysh[i],data1$gysh)
    
    data1$bz[which(data1$bz == TRUE)] <- 1
    
    data1$bz[which(data1$bz == FALSE)] <- 0
    
    print(i)
  }
  else
    break
}

你可能感兴趣的:(R)