我有一张包含不同类型的表格。其中一列是string类型,另一列是整数。 我想逐行检索内容,但我不知道如何告诉R一个列是一个我想要作为字符串来解释的字符串。这是一个最小的运行示例:
# create small toy dataset
a=c("label1", 3, 56, "foo")
b=c("label2", 1, 2, "bar")
d=as.data.frame(rbind(a,b)) # in my original code I have a data.frame
# retrieve a row
e = d[1,]
# take the first column: all is OK
e[1]
# the unexpected stuff:
type(e[1]) # I expected "character" but obtain "list"
unlist(e) # I expected something like "label1"
as.character(e[1]) # I expected something like "label1"
有谁能告诉我发生了什么,我该如何纠正?