Dear BioStars,
I have a genomic ranges (GR) list object called lgr.test
and would like to simply add several columns to its metadata. How would I do that? I have a list of numeric vectors lvec.test
of the same lengths as the GRs in lgr.test
.
Thank you!
> summary(lvec.test)
Length Class Mode
chr1 589 -none- numeric
chr2 790 -none- numeric
chr3 482 -none- numeric
chr4 681 -none- numeric
chr5 698 -none- numeric
chr6 492 -none- numeric
chr7 713 -none- numeric
chr8 489 -none- numeric
chr9 590 -none- numeric
chr10 521 -none- numeric
chr11 853 -none- numeric
chr12 395 -none- numeric
chr13 373 -none- numeric
chr14 358 -none- numeric
chr15 388 -none- numeric
chr16 340 -none- numeric
chr17 465 -none- numeric
chr18 287 -none- numeric
chr19 357 -none- numeric
> summary(lgr.test)
Length Class Mode
chr1 589 GRanges S4
chr2 790 GRanges S4
chr3 482 GRanges S4
chr4 681 GRanges S4
chr5 698 GRanges S4
chr6 492 GRanges S4
chr7 713 GRanges S4
chr8 489 GRanges S4
chr9 590 GRanges S4
chr10 521 GRanges S4
chr11 853 GRanges S4
chr12 395 GRanges S4
chr13 373 GRanges S4
chr14 358 GRanges S4
chr15 388 GRanges S4
chr16 340 GRanges S4
chr17 465 GRanges S4
chr18 287 GRanges S4
chr19 357 GRanges S4
Hi Philipp, thanks for your answer. I tried merge but got an error. I think I have a solution using a for loop, but I'm pretty sure there's a better way to do it using Map, except that my vectors are regular numeric vectors not S4 GR objects. I'll keep hacking at it, but if you have another idea, I'll appreciate it. Thanks!
No worries! What's the error exactly?
You may be able to circumvent it by putting
as.data.frame()
aroundlvec.test
andlgr.test
Hi Philipp, I tried both (with and without
as.data.frame
but get an error referring to a difference in row numbers):arguments imply differing number of rows: 589, 790, 482, 681, 698, 492, 713, 489, 590, 521, 853, 395, 373, 358, 388, 340, 465, 287, 357
Aaah your two tables have different row-lengths - you can try adding
all.x = TRUE
orall.y = TRUE
to the merge command:If all.x is true, all the non matching cases of x are appended to the result as well, with NA filled in the corresponding columns of y; analogously for all.y.