导出到.csv R后字符更改

时间:2018-10-17 04:00:50

标签: r

在理解为什么这些数字以这种方式导出时存在一个问题,但在Rstudio中它们看起来很好。我确定它是文件格式问题,但我不知道如何检查它是什么以及它要导出什么以进行更改。

chr in df

6½ | -105 | 6½ +105

导出后在.csv中

6½ | -105 | 6½ +105

以下代码:

    library(rvest)
    library(dplyr)
    library(tm)
    library(stringi)
    library(readr)


    tomorrow <- Sys.Date()
    tomorrow <- gsub("-", "", tomorrow, fixed=TRUE)

    print(tomorrow)

    url <- read_html(paste0('https://classic.sportsbookreview.com/betting-odds/nhl-hockey/totals/?date=', as.character(tomorrow)))


    rot <- url %>%
      html_nodes('.eventLine-rotation .eventLine-book-value') %>%
      html_text()

    teams <- url %>%
      html_nodes('.team-name a') %>%
      html_text()

    total <- url %>%
      html_nodes('.adjust')%>%
      html_text()

    opening <- url %>%
      html_nodes('.price') %>%
      html_text()

    pinnacle <- url %>%
      html_nodes('.eventLine-book:nth-child(10) b') %>%
      html_text()

    dimes <- url %>%
      html_nodes('.eventLine-book:nth-child(11) b') %>%
      html_text()

    BookMaker <- url %>%
      html_nodes('.eventLine-book:nth-child(12) b') %>%
      html_text()

    BETONLINE <- url %>%
      html_nodes('.eventLine-book:nth-child(13) b') %>%
      html_text()

    BOVADA <- url %>%
      html_nodes('.eventLine-book:nth-child(14) b') %>%
      html_text()

    HERITAGE <- url %>%
      html_nodes('.eventLine-book:nth-child(15) b') %>%
      html_text()

    roster <- data.frame(ROT = rot, TEAM = teams, Total = total, OPENER = opening, PINNACLE = pinnacle,
                          FiveDimes = dimes, BOVADA = BOVADA, BETONLINE = BETONLINE,
                          HERITAGE = HERITAGE, BookMaker = BookMaker)

    write_delim(roster,'NHL_TOTALS_TODAY.csv', delim = ',')

1 个答案:

答案 0 :(得分:1)

我刚刚将您的write_delim更改为write_excel_csv,并按预期在自己的excel中打开了它。

我遇到了同样的错误,只需进行切换即可。

我知道有点晚了。祝你好运,好投注。