Hi All, I am new to bioinformatics and R. I am trying to learn with online tutorials and forums, but could not find anything related to my simple question.
I have a few GRanges defined in R. I wanted to rename the columns of metadata of each of the Granges.
I am using
names(mcols(gr))=c("name1", "name2", "name3")
this works when I try to rename GR individually, but it does not work within a for loop.
for ( gr in c(gr1, gr2, gr3, gr4) ) {
names(mcols(gr)) = c("name1", "name2", "name3")
}
I got this error:
invalid for() loop sequence
Does it mean I can not use for loops for GRs? what am I doing wrong here? what are other ways I can do this?
Did not test your code but inside the loop you're missing a parenthesis right after
gr)
to close thenames
function, and the last double quotes aftername3
is a single quote.names(mcols(gr) = c("name1", "name2", "name3')
should benames(mcols(gr)) = c("name1", "name2", "name3")
this was an error while writing here. But my actual was code properly quoted and with parenthesis. And it does not work