1

I'm just genuinely confused here. So here is some code that works fine:

 insertion3=county$rpc85_weighted.mean[1]-county$rpc85_weighted.mean
  county$changed<-insertion3

I get the column with the values I want. But for some reason, when I make it into a function like this:

differences=function(county) {
  insertion3=county$rpc85_weighted.mean[1]-county$rpc85_weighted.mean
  county$changed<-insertion3
  return(county)
}

It stops at the <-insertion3 line and gives me the error that

Error in `$<-.data.frame`(`*tmp*`, changed, value = integer(0)) : 
  replacement has 0 rows, data has 94 

What's so different about it being a function

Phil
  • 5,491
  • 3
  • 26
  • 61
Nadka
  • 11
  • 2

0 Answers0