Filtering a matrix in R based on values from a single column.

Saturday, July 12, 2014

I have a matrix (600X17) which compares chromosome positions with mutations.On column 3 I have 'Chromosomes' and on 4 I have the corresponding 'Positions'(in bp).There are a total of XVI chromosomes which vary in length.I am looking to trim each chromosome to about 40000bp from both ends.The good thing is that they all begin with 0, so trimming it from the beginning is no problem. However as the lengths of each chromosome vary, I find it hard to trim the chromosomes from the ends. Here is what my matrix looks like. Chromosome Position(bp) chrVII 1005225 chrVII 1005229 chrXII 1005862 chrVII 1006275 chrXV 1013944 chrXV 1015479 chrXII 1031595 chrIV 1033166 chrIII 10332 chrIX 103576 chrXV 103577 chrXII 1038159 chrXII 1038161 chrIX 104223 chrXII 1047927 chrIX 105338 chrIX 105352


The code that I am using to filter the ends.



#Filtering chromosome ends: 40000bp from both ends
#From beginning >40000bp
data.1=annotatedMatrix[annotatedMatrix[,4]>=40000,]
#Variants down to 570 from 653 for individual chromosomes
#Now Filtering each chromsome based on end coordinates.
names <- c("chrI","chrII", "chrIII","chrIV", "chrV","chrVI","chrVII", "chrVIII",
"chrIX", "chrX", "chrXI", "chrXII", "chrXIII", "chrXIV", "chrXV", "chrXVI")
#(Endcoord - 40000bp)
values <- c(190218,773184,276620,1491933,536874,230161,1050940,522643, 399888, 705751,
626816, 1038177, 884431, 744333, 1051291, 908066)
#assign indices
order(c(values))


Any ideas and suggestions would be very helpful.







http://ift.tt/1sKfhSP