R导入带有函数的csv数据

时间:2017-05-16 03:51:11

标签: r function

我想创建我的owm函数来读取var fixtures = { "_links": { "self": { "href": "http://api.football-data.org/v1/fixtures/150840" }, "soccerseason": { "href": "http://api.football-data.org/v1/soccerseasons/426" }, "homeTeam": { "href": "http://api.football-data.org/v1/teams/62" }, "awayTeam": { "href": "http://api.football-data.org/v1/teams/73" } }, "date": "2016-08-13T14:00:00Z", "status": "FINISHED", "matchday": 1, "homeTeamName": "Everton FC", "awayTeamName": "Tottenham Hotspur FC", "result": { "goalsHomeTeam": 1, "goalsAwayTeam": 1 } }; var res = Object.keys(fixtures.result).map(item => { return fixtures.result[item] }); console.log(res);数据。代码是:

.csv

然而,当我阅读我的数据时,我得到了这个my_read_data <- function(x){ data <- data.table::fread(x, header = T, strip.white = T) data <- data[data[5] != 0,] data <- as.Date(data[9]) data <- as.Date(data[16]) }

Error

我想要的是如果Data <- my_read_data("mydata.csv") Error in `[.data.table`(data, data[5] != 0, ) : i is invalid type (matrix). Perhaps in future a 2 column matrix could return a list of elements of DT (in the spirit of A[B] in FAQ 2.14). Please let datatable-help know if you'd like this, or add your comments to FR #657. 出现column 5,请删除该行。设置0格式 有什么建议吗?

更新
感谢@ thelatemail的评论。现在,我在下面编辑我的代码:

Column 9 & 10

但是,my_read_data <- function(x){ data <- data.table::fread(x, header = T, strip.white = T) data <- data[data[[5]] != 0,] data <- as.Date(data[9]) data <- as.Date(data[16]) } 不起作用。运行我的功能后,它不会创建数据。

1 个答案:

答案 0 :(得分:0)

as.date()的工作方式如下,您可以将格式更改为所需的格式

x<- as.Date(dates,format = "%m/%d/%y")