1

I'm struggling with this error about few hours. I'm not sure how to explain my problem well.

the situation is I was preprocessing some 18 cities' overall excel data by year

for example variable1(numeric) variable2(numeric)

year reg     ....
2001 11      ...
2002 21      ...
2I03 22
2004 32

I want to divide by cities, make new variable which represents each variable's average. after that, make new excel sheet city by city.

so... i typed

 for(i in 2:3){
   for(k in 1:9){
      raw_ik <- raw_data %>% 
          filter(reg==ik)

          raw_ik_mean <- raw_data%>% 
          filter(reg==ik) %>% 
          summarise(mean_grGo = mean(grGo))

          ik<- bind_rows(raw_ik,raw_ik_mean)
    }
 }

but, Error in filter_impl(.data, quo) : Result must have length 259, not 399

Thanks in advance.

fool-dev
  • 7,671
  • 9
  • 40
  • 54
lbh0920
  • 13
  • 1
  • 1
  • 3

1 Answers1

5

I just faced similar error and I found the solution easily. It is because you are trying to use a variable that has not been declared. In your case, when you try to use the variable ik in the filter function, which you haven't assigned in your code (as per your code given here). It is not clearly stated what you want to do. It seems you may want to group your data by cities and then do the calculations, if that is what you want to do then you can use the group_by function from dplyr package.

Pulsar_534511
  • 98
  • 1
  • 13