Check whether a factor variable is of type integer or float

Yohan Obadia

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
Yohan Obadia

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.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to Check Whether a Variable is an Integer or Not

From Dev

Check if variable is of type int/Integer

From Dev

Check whether the input is integer float or string or something else?

From Java

Checking whether a variable is an integer or not

From Dev

Check if float value is integer

From Dev

How to I check whether a given variable value is of type string

From Dev

get the integer representation value of a float type variable in C

From Dev

Check whether a property is of type Boolean or not

From Dev

How to check if a variable is an integer?

From Dev

How to check if a variable is an integer?

From Dev

Check if number is of Integer type

From Dev

Check if number is of Integer type

From Dev

Change a dataframe column type from integer to a factor

From Dev

How to check whether a string is an integer in Ruby?

From Dev

How to check whether an Integer is null or zero in Java?

From Dev

Python: True if variable is integer or float

From Dev

Type mismatch: expected Integer but was Float

From Dev

Is GLhalf a float point type or integer?

From Dev

Casting a double or float to an integer type, which type?

From Dev

In R programming, convert factor type to integer type of a column in matrix

From Java

How do I check that a number is float or integer?

From Dev

C - How to check if the number is integer or float?

From Dev

Check empty float or integer value in golang

From Dev

shell script to check if input is a string/integer/float

From Java

How to check if a variable is an integer in JavaScript?

From Dev

php check to see if variable is integer

From Dev

c++ check if integer variable

From Java

Check whether variable is number or string in JavaScript

From Dev

check whether a variable is in increasing order in R

Related Related

  1. 1

    How to Check Whether a Variable is an Integer or Not

  2. 2

    Check if variable is of type int/Integer

  3. 3

    Check whether the input is integer float or string or something else?

  4. 4

    Checking whether a variable is an integer or not

  5. 5

    Check if float value is integer

  6. 6

    How to I check whether a given variable value is of type string

  7. 7

    get the integer representation value of a float type variable in C

  8. 8

    Check whether a property is of type Boolean or not

  9. 9

    How to check if a variable is an integer?

  10. 10

    How to check if a variable is an integer?

  11. 11

    Check if number is of Integer type

  12. 12

    Check if number is of Integer type

  13. 13

    Change a dataframe column type from integer to a factor

  14. 14

    How to check whether a string is an integer in Ruby?

  15. 15

    How to check whether an Integer is null or zero in Java?

  16. 16

    Python: True if variable is integer or float

  17. 17

    Type mismatch: expected Integer but was Float

  18. 18

    Is GLhalf a float point type or integer?

  19. 19

    Casting a double or float to an integer type, which type?

  20. 20

    In R programming, convert factor type to integer type of a column in matrix

  21. 21

    How do I check that a number is float or integer?

  22. 22

    C - How to check if the number is integer or float?

  23. 23

    Check empty float or integer value in golang

  24. 24

    shell script to check if input is a string/integer/float

  25. 25

    How to check if a variable is an integer in JavaScript?

  26. 26

    php check to see if variable is integer

  27. 27

    c++ check if integer variable

  28. 28

    Check whether variable is number or string in JavaScript

  29. 29

    check whether a variable is in increasing order in R

HotTag

Archive