Search code examples
rnumeric

After converting to numeric still not in numeric format in R


I have an issue in converting data into the numeric format.

str(DfFilter)

output

'data.frame':   32 obs. of  5 variables:
 $ InstanceType      : chr  "  c1.xlarge" "  c1.xlarge" "  c1.xlarge" "  c1.xlarge" ...
 $ ProductDescription: chr  "  Linux/UNIX" "  Linux/UNIX" "  Linux/UNIX" "  Linux/UNIX" ...
 $ SpotPrice         : num  0.052 0.0739 0.0747 0.0751 0.0755 ...
 $ ymd_hms(Timestamp): POSIXct, format: "2021-05-16 06:26:40" "2021-05-16 00:58:55" "2021-05-16 06:46:50" ...
 $ Timestamp         : 'times' num  06:26:40 00:58:55 06:46:50 14:17:55 19:07:09 ...
  ..- attr(*, "format")= chr "h:m:s"

but when i run to check for numeric values as follow

is.numeric(DfFilter)
[1] FALSE

why is that so. Kindly help in understanding this issue. Thanks in advance.


Solution

  • With purrr package and based on the comments:

    DfModel <- DfFilter %>% 
      purrr::keep(.p = function(x) is.numeric(x))
    

    It will keep only the numeric variables