<div dir="ltr">Hi, <br>
<br>
Currently I'm trying to find a way to make row wise operation within data.table to find value that have<br>
a certain pattern, and to count those. <br>
<br>
For instance find the number of 3 for each Respid and count those for each row.<br>
set.seed(1)<br>
DT <- data.table( Respid = seq(1,100, 1), <br>
Q1 = rep(1:5, each = 20), <br>
Q2 = as.integer(runif(100, min = 1, max = 5) ),<br>
Q3 = sample(1:5, 100, replace = T)<br>
)<br>
<br>
DT1 <- DT[, lapply(.SD, function(x) length(grep(3, x))), by = 'Respid']<br>
<br>
A do get 1 for each column that has a 3 in it but no column that counts it. <br>
<br>
Regards Serdar</div>