0

有人可以解释一下吗?为什么设置的选项不起作用?为什么默认还是factor,然后就不能绑定数据了?

> options(stringAsFactors = FALSE)
> getOption("stringsAsFactors")
[1] TRUE
> policy.number = c("A00187", "A00300","A00467","A01226")
> issue.age = c(74,30,68,74)
> sex=c("F", "M", "M", "F")
> smoke=c("S","N","N","N")
> face.amount = c(420, 1560, 960, 1190)
> ins.df = data.frame(policy.number, issue.age, sex, smoke, face.amount)
> ins.df = rbind(ins.df, c("A01495", 62, "M", "N", 1330))
Warning message:
In `[<-.factor`(`*tmp*`, ri, value = "A01495") :
  invalid factor level, NAs generated
4

1 回答 1

1

在您的第一行代码中,您忘记了一个 "s" :

options(stringAsFactors = FALSE)

应该 :

options(stringsAsFactors = FALSE)
于 2013-02-03T22:46:20.987 回答