2

My question is simple and hopefully can be answered quickly. I have a code in R that is for calculating home ranges. Everything works except one line of the code, which I've included here:

locoh <- lapply(dat, function(x) rhrLoCoH(x[ c("LONGITUDE", "LATITUDE")]))

The error I get is as follows:

Error in `[.data.frame`(x, c("LONGITUDE", "LATITUDE")) : undefined columns selected

My guess is that I have messed up somewhere with my commas, but I'm not sure where or how to fix it.

  • 1
    right after [ - x[ , c('long', 'lat') ] , assuming you're selecting columns from a data frame? – obrl_soil Jun 8 '17 at 12:20
  • That seemed to do the trick. I also needed to edit another section earlier: – J.W. Powell Jun 8 '17 at 17:17
  • dat <- lapply(fls, read.table, sep = "/t", header = TRUE) needed to be changed to dat <- lapply(fls, read.table, sep = ",", header = TRUE) – J.W. Powell Jun 8 '17 at 17:18
  • 1
    @orbl_soil, go ahead and answer the question if you'd like a green check mark. – J.W. Powell Jun 8 '17 at 17:19
  • Related post: stackoverflow.com/questions/19205806/… – zx8754 Dec 28 '17 at 21:16
1

Add your comma right after [ - x[ , c('long', 'lat') ] as you are selecting columns.

We're looking for long answers that provide some explanation and context. Don't just give a one-line answer; explain why your answer is right, ideally with citations. Answers that don't include explanations may be removed.

  • Please edit your answer and add more explanation, showing the problem code and the corrected code. – Simbamangu Jun 10 '17 at 7:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.