Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

R: Error applied to an object of class "c('integer', 'numeric')"

Tags:

I i am using the following code to increase the next observation by the previous observation * .5:

abc <- data.frame(1:6)
abc$b <- 0
colnames(abc) <- c ("imps","Effect")  

abc$Effect <- filter(abc$imps, filter = 0.5, method = "recursive")

I keep getting the error:

Error in UseMethod("filter_") : 
  no applicable method for 'filter_' applied to an object of class "c('integer', 'numeric')"

The desired output:

imps    Effect
1   1
2   2.5
3   4.25
4   6.125
5   8.0625
6   10.03125

Any suggestions? NOTE: Yesterday before I installed 3.2.5 from 3.2.2 this ran just fine

like image 200
cesco Avatar asked Jul 03 '17 15:07

cesco


1 Answers

You can also use Reduce to do what you want:

abc$Effect = Reduce(function(i,j) j+i*0.5,abc$imps,accumulate=T)
  imps   Effect
1    1  1.00000
2    2  2.50000
3    3  4.25000
4    4  6.12500
5    5  8.06250
6    6 10.03125

Your issue can come from the fact that the dplyr library is masking the filter function, in which case, you should precise stats::filter(..).

like image 198
Lamia Avatar answered Sep 24 '22 16:09

Lamia