[Solved] Create vectors containing 0 or 1 based on subjects in R [closed]
t( apply(mydf[-1], 1, function(x) as.numeric ( c( # need the t() to change columns to rows any( grepl(“POLLUTION|EMISSION|WASTE”, x) ), any(grepl(“OIL\\sSPILL”, x) ), any(grepl(“MERGER|ACQUI”, x) ), any(grepl(“MERGER|ACQUI”, x) ) ) ) ) ) #——- [,1] [,2] [,3] [,4] [1,] 1 0 0 0 [2,] 1 0 1 1 [3,] 1 1 0 0 [4,] 1 … Read more