The initial matrix looks like this:
1 A 1
1 B 1
1 C 1
2 A 1
3 A 1
3 C 1
It is necessary to bring to mind:
A B C
1 1 1 1
2 1 0 0
3 1 0 1
I am using a code like:
for (i in 1:length(t_data$cid)) {
t_cid <- t_data$cid[i]
t_val <- t_data$eventAction[i]
df_events[grep(t_cid, df_events$cid),grep(paste0("^",t_val,"$"), colnames(df_events))] <- 1
print(i)
}
But we are talking about more than a million rows in the first matrix and a hundred columns in the second. About 10k rows in 5 mins, too slow. Please help.