简体   繁体   中英

How to read file in R with column names having brackets?

I have one input file.

cat file

      IstCol (ABC) IInd COl (DEF) 
      34           45 
      32           45

      > input<-read.table("file",sep="\t",header=TRUE)
      > input
      IstCol..ABC..IInd.COl..DEF.
      1            34           45 
      2             32           45

But it does not recognise brackets. What changes need to be made to recognize it?

read.table is by default checking if column names are valid variable names and if they are unique, you can turn it off by setting check.names = F :

input <- read.table("file", sep="\t", header=T, check.names=F)

Column names matter if you would like to use $ operator to call the variables. Description from manual :

check.names: logical.  If 'TRUE' then the names of the variables in the
          data frame are checked to ensure that they are syntactically
          valid variable names.  If necessary they are adjusted (by
          'make.names') so that they are, and also to ensure that there
          are no duplicates.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM