I have the following data frame:
library(tidyverse)
df <- tribble(
~sname, ~seq,
"foo", "TTAW",
"bar", "ACTN",
"qux", "AAAA"
)
df
What I want is to have 3rd column that locate the positions of "T" in every row. The end result looks like this:
sname seq t_pos
foo TTAW 1,2
bar ACTN 3
qux AAAA 0
How can I achieve that? I tried this but doesn't work:
df %>%
dplyr::mutate(t_pos = paste0( list(which(strsplit(seq, "")[[1]] == "T") ) ))
What's the right way to do it?