在R中加载包含变量空间的excel文件

时间:2015-06-04 23:03:45

标签: r read.table

我有一个excel文件,如下所示:

A    B         C    
ID   Name  Description
 1   Jane  She is the headmaster of the school

现在我想把它加载到R. 我已将excel文件保存为文本,并在以下命令中键入:

df<-read.table("excelFileName.txt", header=T)
然后,R会抱怨列数多于列标题。如果我想将最后一个变量保留为字符串,我该怎么做?是否仍然可以在R?

中加载文件

1 个答案:

答案 0 :(得分:0)

当前的txt(csv)文件:

   A    B                                   C
1 ID Name                          Description
2  1 Jane She is the headmaster of the school

示例数据集:

df <- structure(list(A = structure(c(2L, 1L), .Label = c("1", "ID"), class = "factor"), 
    B = structure(c(2L, 1L), .Label = c("Jane", "Name"), class = "factor"), 
    C = structure(1:2, .Label = c("Description", "She is the headmaster of the school"
    ), class = "factor")), .Names = c("A", "B", "C"), class = "data.frame", row.names = c(NA, 
-2L))

Read.table:

df<-read.table("excelFileName.txt", header=T, sep = ",")