Suppose you have a data frame:
TF_name L R
A 1 5
B 10 15
C 17 18
What would be the best way to manipulate this in such a way to make it look like this?
TF_name Position
A 1
A 2
A 3
A 4
A 5
B 10
B 11
B 12
B 13
B 14
B 15
C 17
C 18
EDIT: I've been trying out all the answers, however none seem to work on this particular data frame v
. Is the way I am creating the data frame why these methods are not working?
f <- 'GADANCGGCCTAGATGTGAT'
motifs = c('GA','GC','CT','AG','AT')
v <- na.omit(data.frame(do.call(rbind, lapply(stri_locate_all_regex(f, motifs), unlist))))
v <- data.frame(v,Legend=na.omit(unlist(stri_extract_all_regex(f,motifs))))
v <- v[order(v[,1]),]
v <- v[c(3,1,2)]
organizer <- function(df,tracknom) {
names(df)<-c("V1","V2","V3")
newdf <- data.frame(
Name=rep(df$V1, df$V3-df$V2 + 1),
Track=tracknom,
Position=unlist(mapply(seq, df$V2, df$V3))
)
newdf
}
v <- organizer(v,1)
v
Name Track Position.1 Position.2 Position.3 Position.4 Position.5 Position.6 Position.7 Position.8
1 GA 1 1 8 10 12 13 14 18 19
2 GA 1 2 9 11 13 14 15 19 20
3 GC 1 1 8 10 12 13 14 18 19
4 GC 1 2 9 11 13 14 15 19 20
5 CT 1 1 8 10 12 13 14 18 19
6 CT 1 2 9 11 13 14 15 19 20
7 AG 1 1 8 10 12 13 14 18 19
8 AG 1 2 9 11 13 14 15 19 20
9 GA 1 1 8 10 12 13 14 18 19
10 GA 1 2 9 11 13 14 15 19 20
11 AT 1 1 8 10 12 13 14 18 19
12 AT 1 2 9 11 13 14 15 19 20
13 GA 1 1 8 10 12 13 14 18 19
14 GA 1 2 9 11 13 14 15 19 20
15 AT 1 1 8 10 12 13 14 18 19