需要我在R编程中使用正则表达式清理字符串

时间:2018-12-20 11:07:27

标签: r nsregularexpression

我的字符串如下。

[{\"period\":\"01-06-2018\",\"count\":5},{\"period\":\"01-07-2018\",\"count\":8},{\"period\":\"01-08-2018\",\"count\":9}]

但是我只希望(仅反斜杠)被删除,它应该如下所示 (使用 R编程函数)

[{"period":"01-06-2018","count":5},{"period":"01-07-2018","count":8},{"period":"01-08-2018","count":9}]

1 个答案:

答案 0 :(得分:0)

这应该做到:

library(tidyverse)
somestring<-c("[{\"period\":\"01-06-2018\",\"count\":5},{\"period\":\"01-07-2018\",\"count\":8},{\"period\":\"01-08-2018\",\"count\":9}]")

library(jsonlite)
fromJSON(somestring)

这将产生:

   period count
1 01-06-2018     5
2 01-07-2018     8
3 01-08-2018     9