如何读取R中的文件,列名是否有括号?

时间:2013-03-04 04:43:45

标签: r file brackets

我有一个输入文件。

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

但它不承认括号。认识到需要做出哪些改变?

1 个答案:

答案 0 :(得分:0)

read.table默认情况下检查列名是否为有效变量名称,如果它们是唯一的,您可以通过设置check.names = F来关闭它:

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

如果您想使用$运算符来调用变量,则列名很重要。手册说明:

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.