即使使用 stringsAsFactors = F 也无法阻止 R 将 .csv 文件作为因子读取? | 珊瑚贝

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\\'”

我们将不胜感激。

  • 这是一个错字:row.names = False 应该是 row.names = False。
  • 哦,谢谢。但是,它返回”未使用的参数(stringsAsFactors = FALSE)”
  • 新错误可能是针对 write.csv 的,因为它没有 stringsAsFactors 参数。
  • 尝试全局设置选项。在运行代码之前:options(stringsAsFactors=F)。
  • 为什么要指定 sep=””?你知道 CSV 代表什么,对吧?


你可以试试这个:

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 …

来源:https://www.codenong.com/42561497/

微信公众号
手机浏览(小程序)

Warning: get_headers(): SSL operation failed with code 1. OpenSSL Error messages: error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(): Failed to enable crypto in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57

Warning: get_headers(https://static.shanhubei.com/qrcode/qrcode_viewid_8964.jpg): failed to open stream: operation failed in /mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line 57
0
分享到:
没有账号? 忘记密码?