Hi every body! I'm trying to perform an R loop to processes one of my data frame in which I've stored ChiP seq data. My data frame looks like this
chr1 700245 714068 - 13824 uc001abo.3
chr1 934342 935552 - 1211 uc001aci.2
chr1 1189292 1203372 - 14081 uc001adm.4
chr1 1189292 1209234 - 19943 uc001ado.3
chr1 1243994 1247057 + 3064 uc001aed.3
And I want to handle the 2nd and 3rd columns (adding and subtracting some values). To do that, I've create the code as follow:
import_file= read.delim("file", sep="\t", header = F)
file =as.data.frame.matrix(import_file)
#length( file$V6)
for (i in length file$V6)){
if (any( file$V4 == '-')) {
file$V2 = file$V3-150
file$V3 = file$V3 +50
}
else {
#if file$V4 == '+' do this
file$V2 = file$V2-50
file$V3 = file$V2 +150
}
}
The first "if" statement is processed fine, but for "else", the loop repeat the "if" statement for the other condition. What I want to do is
if (any( file$V4 == '-')) {
file$V2 = file$V3-150
file$V3 = file$V3 +50
#works
and
if file$V4 == '+' do this
file$V2 = file$V2-50
file$V3 = file$V2 +150
#doesn't work
Any help?
Thanks a lot!
Hi guys, your approaches perform the calculation over the modified data (after adding or subtracting) not over the original data frame (that is exactly what I want) :)
Please use
ADD COMMENT/ADD REPLY
(or add this to the original question) to keep threads logically organized.