Can't stop R from reading .csv files as factors even with stringsAsFactors = F?
我有一个如下所示的 CSV 文件:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | t.trend.dates. sig 2/23/2017 2 2/23/2017 4 2/23/2017 6 2/23/2017 8 2/23/2017 9 2/23/2017 11 2/23/2017 12 2/23/2017 13 2/22/2017 14 2/23/2017 15 2/23/2017 16 2/23/2017 17 2/23/2017 18 2/23/2017 19 2/23/2017 20 2/23/2017 21 2/22/2017 24 |
我已经使用
将它读入 R
1 | TrendIndices <- read.csv("TrendingSignals.csv", header = TRUE, sep="") |
这会返回
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | t.trend.dates. X..sig. 1 2017-02-23 ,2 2 2017-02-23 ,4 3 2017-02-23 ,6 4 2017-02-23 ,8 5 2017-02-23 ,9 6 2017-02-23 ,11 7 2017-02-23 ,12 8 2017-02-23 ,13 9 2017-02-22 ,14 10 2017-02-23 ,15 11 2017-02-23 ,16 12 2017-02-23 ,17 13 2017-02-23 ,18 14 2017-02-23 ,19 15 2017-02-23 ,20 16 2017-02-23 ,21 17 2017-02-22 ,24 > str(TrendIndices) 'data.frame': 17 obs. of 2 variables: $ t.trend.dates.: Factor w/ 2 levels"2017-02-22","2017-02-23": 2 2 2 2 2 2 2 2 1 2 ... $ X..sig. : Factor w/ 17 levels",11",",12",",13",..: 10 14 15 16 17 1 2 3 4 5 ... |
我都试过了
1 2 | write.csv(sig.trend, file="TrendingSignals", row.names = False, stringsAsFactors=FALSE) TrendIndices <- read.csv("TrendingSignals.csv", header = TRUE, sep="", stringsAsFactors=FALSE) |
但我不断收到错误"评估中的错误(expr,envir,enclos):找不到对象\\'False\\'"
我们将不胜感激。
你可以试试这个:
1 2 | TrendIndices <- read.table("TrendingSignals.csv", sep ="" , header = TRUE , stringsAsFactors= FALSE) |
给予:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 | > TrendIndices t.trend.dates. sig 1 2/23/2017 2 2 2/23/2017 4 3 2/23/2017 6 4 2/23/2017 8 5 2/23/2017 9 6 2/23/2017 11 7 2/23/2017 12 8 2/23/2017 13 9 2/22/2017 14 10 2/23/2017 15 11 2/23/2017 16 12 2/23/2017 17 13 2/23/2017 18 14 2/23/2017 19 15 2/23/2017 20 16 2/23/2017 21 17 2/22/2017 24 > str(TrendIndices) 'data.frame': 17 obs. of 2 variables: $ t.trend.dates.: chr "2/23/2017""2/23/2017""2/23/2017""2/23/2017" ... $ sig : int 2 4 6 8 9 11 12 13 14 15 ... |