Re: [R] search across a row for strings

2015-06-15 Thread David Winsemius
On Jun 15, 2015, at 1:12 PM, Federman, Douglas wrote: > I'm trying to do the following: search each patient's list of diagnoses for a > specific code then create a new column based upon the the presence of the > specific code. > Simplified data follows: > > con <- textConnection(" > IDDX

Re: [R] search across a row for strings

2015-06-15 Thread Sarah Goslee
This faster than your version, and doesn't return NA: df$htn <- apply(df[,2:4], 1, function(x)any(grepl("^410", x))) > df ID DX1 DX2 DX3 htn 1 1 4109 4280 7102 TRUE 2 2 734 311 490 FALSE 3 3 4011 42822 4101 TRUE > system.time({ + for(j in 1:1) { + for (i in 1:nrow(df)) {

[R] search across a row for strings

2015-06-15 Thread Federman, Douglas
I'm trying to do the following: search each patient's list of diagnoses for a specific code then create a new column based upon the the presence of the specific code. Simplified data follows: con <- textConnection(" ID DX1 DX2 DX3 1 410942807102 2 734 311