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

Loading excel file with a variable containg space in R

我有一个 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 中加载文件?

当前的 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 = ",")