[R] counting characters starting point

Rui Barradas rui1174 at sapo.pt
Tue Feb 21 00:41:55 CET 2012


Hello,

Try

seq1 <- 'PQRTUWXY'
seq2 <- 'AQSDSSDHRS'
seq3 <- 'EEZYJKFFBHO' 

ref1 <- 'U'
ref2 <- 'S'
ref3 <- 'Y'

fun <- function(seq, chr){
	f <- function(x, seq, chr){
		pos <- regexpr(x, seq)
		if(pos < 0)
			99
		else
			as.integer(pos - regexpr(chr, seq))
	}
	sapply(LETTERS, f, seq, chr)
}

rbind(
	fun(seq1, ref1),
	fun(seq2, ref2),
	fun(seq3, ref3)
)

Hope this helps,

Rui Barradas


--
View this message in context: http://r.789695.n4.nabble.com/counting-characters-starting-point-tp4405233p4405475.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list