Dear All,
I wanted to replace highest value in data frame (e.g a = data.frame(10,2,3,99,4,56,9,10) ) to 0, and also I want to convert surrounding index values ( e.g max(a) = 99 , so I want to convert surrounding 5 index values on each side of maximum value to 0).
I tired to replace it this way,
> a = data.frame(10,2,3,4,56,9,10,99)
> a = as.numeric(a)
> a
> [1] 10 2 3 4 56 9 10 99
> a = replace(a,c((which(a==max(a))-1):(which(a==max(a))+1)),0)
> a
> [1] 10 2 3 4 56 9 0 0 0
>
But this approach is changing the size of my data frame.
In my real data the size of data frame always changes and max(value of data frame) could be first or even last value. But I want to usually replace max(data.frame) and its surrounding (+40 and -40) index values to be zero without changing the size of data frame.
I am having am error when I am trying to replace some index values in a data frame to 0.
Error in x[list] <- values : only 0's may be mixed with negative subscripts
I figured out why this error is coming.
Could you help me in solving this problem.
Thank You,
Best Regards
Shri