How do you cast a double to an integer in R?

后端 未结 4 1091
南笙
南笙 2021-02-13 03:04

My question is: Suppose you have computed an algorithm that gives the number of iterations and you would like to print the number of iterations out. But the output always many d

4条回答
  •  星月不相逢
    2021-02-13 03:55

    If you have a numeric matrix you wish to coerce to an integer matrix (e.g., you are creating a set of dummy variables from a factor), as.integer(matrix_object) will coerce the matrix to a vector, which is not what you want. Instead, you can use storage.mode(matrix_object) <- "integer" to maintain the matrix form.

提交回复
热议问题