In R, I am trying to write a function to subset and exclude observations in a data frame based on three variables. My data looks something like this:
data.frame': 43 obs. of 8 variables:
$ V1: chr "ENSG00000008438" "ENSG00000048462" "ENSG00000006075" "ENSG00000049130" ...
$ V2: chr "ENST00000008938" "ENST00000053243" "ENST00000225245" "ENST00000228280" ...
$ V3: chr "ENSP00000008938" "ENSP00000053243" "ENSP00000225245" "ENSP00000228280" ...
$ V4: chr "PGLYRP1" "TNFRSF17" "CCL3" "KITLG" ...
$ V5: chr "19" "16" "17" "12" ...
$ V6: chr "q13.32" "p13.13" "q12" "q21.32" ...
$ V7: int 46522415 12058964 34415602 88886566 8276226 150285143 29138654 76424442 136871919 6664568 ...
$ V8: int 46526304 12061925 34417515 88974238 8291203 150294844 29190208 76448092 136875735 6670599 ...
>
What I am trying to do is this:
input = function(x) {
pruned1 <- subset(x[-which(x$V5 == 1 & x$V7 > 113818477 & x$V8 < 114658477), ])
pruned2 <- subset(pruned1[-which(pruned1$V5 == 1 & pruned1$V7 > 192461456 & pruned1$V8 < 192549912), ])
# and so on
}
So I want to take my original data frame, exlude observations that fulfil all three of the subsetting conditions, make a new object of the remaining observations (pruned1) and exclude any observations that fulfil a new set of condidtions and so on.
The problem I am having seems to be the third condition in the first subsetting, as this returns:
'data.frame': 1 obs. of 8 variables:
$ V1: chr NA
$ V2: chr NA
$ V3: chr NA
$ V4: chr NA
$ V5: chr NA
$ V6: chr NA
$ V7: int NA
$ V8: int NA
While only using the first two conditions returns:
'data.frame': 38 obs. of 8 variables:
$ V1: chr "ENSG00000008438" "ENSG00000048462" "ENSG00000006075" "ENSG00000049130" ...
$ V2: chr "ENST00000008938" "ENST00000053243" "ENST00000225245" "ENST00000228280" ...
$ V3: chr "ENSP00000008938" "ENSP00000053243" "ENSP00000225245" "ENSP00000228280" ...
$ V4: chr "PGLYRP1" "TNFRSF17" "CCL3" "KITLG" ...
$ V5: chr "19" "16" "17" "12" ...
$ V6: chr "q13.32" "p13.13" "q12" "q21.32" ...
$ V7: int 46522415 12058964 34415602 88886566 8276226 150285143 29138654 76424442 136871919 6664568 ...
$ V8: int 46526304 12061925 34417515 88974238 8291203 150294844 29190208 76448092 136875735 6670599 ...
>
Doing this manually is not an options, since I have a large number of input files that I would like so prune in the same manner.
Thanks in advance for any help!