r - Test for multiple strings in multiple columns -


I have searched extensively on stack overflow without getting the answer to the following question: I look for a function that I Examines if there are any special strings in some columns.

  # I'm looking for a barrier for heart attack & lt; - c ("b", "c") # I am also looking for stroke stroke & lt; - c ("h", "i") #sample Data set set.seed (1234) dat < - data.frame (A = sample ([1: 9], 10, true), B = sample (letters [1: 9], 10, truth), C = sample (letter [1: 9], 10, Truth =), sample = (sample [1: 9], 10, true), DATE = sample. Int (10, size = 10, change = FALSE)) # I have tried many things from them: # First one Using dplyr package. Inflation = Eiffel (% (% A, C ("A", "B", "C", "D")], DATE, NFLS contains some lines from mutation ... # I also have grep (paste Infrarence, fall = "|"), date [, 1: 4], value = TRUE), DATE, NA))   

. I can get it to work if I check in only one column or just look after one of the stars. But I need to see if any of the wires are included in any of the columns, and in that case the date value is returned as a new variable.

Any help is greatly appreciated.

The following can help:

  & gt; [1: 5], x [5], NA) [1], [2] [, 3] [, 4] [, 5]] [, 6] [, 7] [, 8] [, 9] In the data.frame form:  
  [6] [1,] "6" NA "3" NA "2" NA "7" NA "1" NA [2,] " 6 "" 10 "" 3 "NA" 2 "NA" 7 "" 9 "NA" 4 "  

& gt; As.data.frame (T (Applied (data, 1, function (x) effecension (% x [5], NA) in iphail (% x [1: 5]))) V1 V2 1 6 6 2 & Gt; NA & gt; 10 3 3 3 4 & lt; NA & gt; & Lt; NA & gt; 5 2 2 6 & lt; NA & gt; & Lt; NA & gt; 7 7 7 8 & lt; NA & gt; 9 9 & lt; NA & gt; 10 & lt; NA & gt; 4

For strokes:

  & gt; As.data.frame (T (Applied (data, 1, function (x) ifelse (stroke %% x [1: 5], x [5], NA)))) V1 V2 1 & gt; NA & gt; & Lt; NA & gt; 2 & lt; NA & gt; & Lt; NA & gt; 3 & lt; NA & gt; & Lt; NA & gt; 4 & lt; NA & gt; 5 5 2 & lt; NA & gt; 6 8 & lt; NA & gt; 7 & lt; NA & gt; & Lt; NA & gt; 8 & lt; NA & gt; 9 9 1 1 10 4 & lt; NA & gt;    

Comments

Popular posts from this blog

java - ImportError: No module named py4j.java_gateway -

python - Receiving "KeyError" after decoding json result from url -

.net - Creating a new Queue Manager and Queue in Websphere MQ (using C#) -