as.integer(vector) changes the vector, even though it contains only round values (in r) -


When I change a vector of 0 and changes 1s to R, then this varies the vector and its values Changes to

Table (forecast)

  Forecast 0 1 318 133  

as.integer (forecast)

  [1] 2 1 1 2 1 2 2 1 2 1 1 1 1 1 1 1 2 2 1 1 1 1 1 1 1 1 1 1 2 1 1 2 2 2 1 1 1 1 2 1 1 1 1 1 1 2 2 1 1 1 1 1 1 1 1 1 2 1 2 1 1 2 2 1 2 1 2 1 1 1 1 2 1 1 2 1 2 1 2 1 1 2 1 1 2 1 1 1 2 1 1 2 1 2 1 2 1 2 2 [102] 1 1 1 1 1 2 1 1 2 1 1 1 2 1 2 1 2 2 1 1 1 1 2 1 1 1 1 1 1 2 1 2 1 1 2 2 2 1 2 2 1 1 1 2 1 1 1 1 1 2 1 2 1 1 2 1 1 1 2 1 1 1 1 1 1 2 2 1 1 2 1 1 2 1 2 2 1 1 1 1 1 1 1 1 2 1 1 1 1 1 1 1 2 1 1 1 2 2 [203] 1 1 2 1 1 1 2 2 1 2 1 2 1 1 2 1 1 1 1 1 1 1 1 1 1 1 2 2 1 1 1 1 1 1 2 1 1 2 1 1 1 1 1 1 1 1 1 2 1 2 1 1 1 1 1 2 1 1 2 1 2 1 1 2 1 2 1 2 1 1 1 1 1 2 2 1 1 2 1 1 1 1 1 2 2 1 2 2 1 1 1 1 1 1 1 1 1 2 2 [304] 1 1 1 2 1 1 2 1 1 2 2 1 1 1 2 1 1 1 2 1 2 1 2 1 1 1 1 2 1 2 1 1 2 1 2 2 1 2 1 2 1 2 2 2 1 1 1 2 1 1 1 1 1 1 2 1 [405] 1 1 1 1 1 2 1 1 2 2 2 2 2 1 2 1 1 2 1 1 2 2 1 1 1 1 2 1 1 2 2 1 1 1 2 2 1 2 1 1 2 1 2 2 1 1  

Predict is a factor:

  & gt; Prediction & lt; - factor (C (0, 0, 1, 1)) gt; Table (forecast) Forecast 0 1 2 2 & gt; As.integer (forecast) [1] 1 1 2 2  

Maybe you want to:

  & gt; As.integer (as.character (forecast)) [1] 0 0 1 1  

Comments