R studio turns numbers into "TRUE"

I downloaded an xlsx file from Googlesheets after adding more data to it and now all the new columns don't have their numeric data appear in Rstudio. Instead the Column observations list either "TRUE" or "FALSE" i'm not quite sure why i assume it has something to do with how it reads the column data.

So downloaded it as a cvs file and it didn't have the issue when it was an xlsx file interesting development and learning experience

I don't know how you have imported the xlsx file into Rstudio, but it appears that the numeric column has been converted to a logical representation.

df <- data.frame(
  values       =            c(-2, -1, 0, 1, 2),
  val_logical  = as.logical(c(-2, -1, 0, 1, 2))
#>   values       val_logical
#> 1           -2        TRUE
#> 2           -1        TRUE
#> 3            0       FALSE
#> 4            1        TRUE
#> 5            2        TRUE
#> 'data.frame':    5 obs. of  2 variables:
#>  $ values      : num  -2 -1 0 1 2
#>  $ val_logical : logi  TRUE TRUE FALSE TRUE TRUE

Created on 2021-02-01 by the reprex package (v1.0.0)

You might find the readxl package quite helpful as it, if needed, also offers a way of specifying explicitely the column types.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.