Entering edit mode
4.1 years ago
selplat21
▴
20
File1_Col1 <- c("Chr1", "Chr2", "Chr3", "Chr4", "Chr5")
File1_Col2 <- c(10000, 8000, 5000, 2000, 500)
File1 <- data.frame(File1_Col1, File1_Col2)
File2_Col1 <- c("Chr1", "Chr1", "Chr1", "Chr2", "Chr2", "Chr2","Chr3", "Chr3", "Chr3"
,"Chr4", "Chr4", "Chr4","Chr5", "Chr5", "Chr5")
File2_Col2 <- c(1,5,7,2,3,5,3,4,5,1,3,6,2,4,5)
File2 <- data.frame(File2_Col1, File2_Col2)
I have two files: File 1 contains chromosomes and their sizes and File 2 contains a list of SNPs for each chromosome.
I need to have the SNPs consecutive by position, so for example:
Chr3 SNP 3 should actually be 3+(the size of both preceding chromosomes) = 3+10000+8000= 18003
Can someone help me write a loop in R that will just sum the sizes of preceding chromosomes in File2_Col2?
What have you tried? You should look at calculating
cumsum
for the first data frame followed by amerge
, then you can create a derived field that is the sum of the theCol2
field.Thank you so much that answers my question!