I want to create a new column in my data frame that is either TRUE or FALSE depending on whether the term has two specified columns. Here are some sample data:
AB <- c('CHINAS PARTY CONGRESS','JAPAN-US RELATIONS','JAPAN TRIES TO')
TI <- c('AMERICAN FOREIGN POLICY', 'CHINESE ATTEMPTS TO', 'BRITAIN HAS TEA')
AU <- c('AUTHOR 1', 'AUTHOR 2','AUTHOR 3')
M <- data.frame(AB,TI,AU)
I can do this for one column or the other, but I cannot figure out how to do this for both. In other words, I do not know how to combine these two lines, which will not mutually correspond with each other.
M$China <- mapply(grepl, "CHINA|CHINESE|SINO", x=M$AB)
M$China <- mapply(grepl, "CHINA|CHINESE|SINO", x=M$TI)
It is important that I specify the columns, I can not select the entire data.frame file. I searched for other similar questions, but none of them apply to my case, and I could not adapt existing examples. Here's what would be helpful to me:
M$China <- mapply(grepl, "CHINA|CHINESE|SINO", x=(M$AB|M$TI)
source
share