rtypes

Automatically read a column of lowercases True and False as logical


Is there any way to read data in a file and automatically convert columns that contains only "True" and "False" in logical ? It works for "T/F" or uppercase "TRUE/FALSE", but not "True/False", which is unfortunately the way Python write it.

EDIT: @Roland's solution works well, but another one I found is the function read_table from the readr package. So there's at least two function that automatically convert lowercase "True/false" in logical when reading data in a file:

data.table::fread()
readr::read_table()

Solution

  • Just use data.table::fread.

    library(data.table)
    fread("x
          True
          False")
    #        x
    #   <lgcl>
    #1:   TRUE
    #2:  FALSE