I have a vector of numbers that can either be of type integer or double globals$out$data$randrating
After I turn it into a table, the same values return an integer as it is of class factor, whatever the values stored in data_rating$rating:
> data_rating <- as.data.frame(table(globals$out$data$randrating))
> colnames(data_rating) <- c("rating", "freq")
> class(data_rating$rating)
[1] "factor"
> typeof(data_rating$rating)
[1] "integer"
How can I check whether those data are of type integer or float ?
Here a previous question that led to this one.
UPDATING THE QUESTION WITH REPRODUCIBLE DATA
> data_rating
| rating | freq
1 | 4 | 312
2 | 7.1 | 324
3 | 8 | 340
4 | 8.5 | 962
5 | 8.7 | 1640
Using the following code you can check whether the data are of type integer or not after being converted to a numeric format :
all.equal(as.numeric(levels(data_rating$rating)),
as.integer(as.numeric(levels(data_rating$rating)))) == TRUE
If that operation returns TRUE
then it is an integer, if it returns FALSE
it is a float.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments