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.


Solution

  • Just use data.table::fread.

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