I have a data frame df that looks like the following:
structure(list(sequence = c("CSPPPPSPSPHPRPP", "GEGSPTSPTSPKQPG", "EAGAPAGSGAPPPAD", "PAPPKPKESKEPENA", "AKPKQQDEDPDGAAE", "GDRGGGTGNEDDDYE" ), group = c("BP", "BP", "BP", "BP", "BP", "BP")), .Names = c("sequence", "group"), row.names = c(NA, -6L), class = c("tbl_df", "tbl", "data.frame")) For all the character variables underdf$sequence I want to get all the possible sub-sets of 7 characters, shifting one character to the right after each iteration. For that, I created a function called scan_core_OLpeptides. If I apply the following function:
scan_core_OLpeptides <- function(x) { for(i in seq_len(nchar(x)-7+1)){ print(str_sub(string = x, start = i, end = i+6)) }} I get the following output:
[1] "CSPPPPS" "GEGSPTS" "EAGAPAG" "PAPPKPK" "AKPKQQD" "GDRGGGT" [1] "SPPPPSP" "EGSPTSP" "AGAPAGS" "APPKPKE" "KPKQQDE" "DRGGGTG" [1] "PPPPSPS" "GSPTSPT" "GAPAGSG" "PPKPKES" "PKQQDED" "RGGGTGN" [1] "PPPSPSP" "SPTSPTS" "APAGSGA" "PKPKESK" "KQQDEDP" "GGGTGNE" [1] "PPSPSPH" "PTSPTSP" "PAGSGAP" "KPKESKE" "QQDEDPD" "GGTGNED" [1] "PSPSPHP" "TSPTSPK" "AGSGAPP" "PKESKEP" "QDEDPDG" "GTGNEDD" [1] "SPSPHPR" "SPTSPKQ" "GSGAPPP" "KESKEPE" "DEDPDGA" "TGNEDDD" [1] "PSPHPRP" "PTSPKQP" "SGAPPPA" "ESKEPEN" "EDPDGAA" "GNEDDDY" [1] "SPHPRPP" "TSPKQPG" "GAPPPAD" "SKEPENA" "DPDGAAE" "NEDDDYE" Which is exactly what I want. However, I wanted to store this output into an object, preferably into a vector or into a data.frame. I thought about storing into a list but it did not work.
applyto get it int to an object or create an object in for loop and pass the output to that