0

I have a dataframe with a set of genomic co-ordinates. I wish to find genes around those co-ordinates using nearest.gene() which print result one at a time. I have been struggling to run the function in a loop:

apply(gene_lst, 1, function (x) nearest.gene(chr=gene_lst$Chr, pos=gene_lst$Pos))
      1       2       3       4       5       6       7       8       9      10 
"ACBD3" "ACBD3" "ACBD3" "ACBD3" "ACBD3" "ACBD3" "ACBD3" "ACBD3" "ACBD3" "ACBD3"

It is overwriting the first output for the next nine co-ordinates. Is there a better way to run this function?

5
  • In your apply function, you didn't pass x into your function nearest.gene() Commented Feb 5, 2020 at 13:52
  • Thanks for pointing that out. Commented Feb 6, 2020 at 22:59
  • Does it solve the problem? Hopefully it works well... Commented Feb 7, 2020 at 7:38
  • Yes, it did. Thanks again for your help. Commented Feb 8, 2020 at 10:56
  • That's great! If you think my answer is helpful, please feel free to upvote/accept it. Thanks :) Commented Feb 8, 2020 at 21:10

1 Answer 1

1

I guess you can have a try with the following code, where you should pass x into your function nearest.gene()

apply(gene_lst, 1, function (x) nearest.gene(chr=x["Chr"], pos=x["Pos"]))
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.