web-dev-qa-db-ja.com

次のエラーを解決するにはどうすればよいですか?入力は、任意の長さの文字ベクトルまたは文字ベクトルのリストである必要があります。

私はRプロジェクトに取り組んでいます。私が使用したデータセットは、次のリンクから入手できます https://www.kaggle.com/ranjitha1/hotel-reviews-city-chennai/data

私が使用したコードはです。

df1 = read.csv("chennai.csv", header = TRUE)
library(tidytext)
tidy_books <- df1 %>% unnest_tokens(Word,Review_Text)

ここでReview_Textはテキスト列です。それでも、次のエラーが発生します。

Error in check_input(x) : 
Input must be a character vector of any length or a list of character
vectors, each of which has a length of 1.
5
Varun Raghav B

stringsAsFactorsが再びストライキします!

エラーメッセージで関数に必要なことが示されているため、Review_Text列は要素であり、文字ベクトルではありません。

デフォルトのreadr::read_csvより高速で、デフォルトではこの問題が発生しないため、read.csvを使用することを強くお勧めします。それ以外の場合は、stringsAsFactorsFALSEに設定するだけで問題ありません。

> tidytext::unnest_tokens(readr::read_csv("chennai_reviews.csv"), Word, Review_Text)
Parsed with column specification:
cols(
  Hotel_name = col_character(),
  Review_Title = col_character(),
  Review_Text = col_character(),
  Sentiment = col_character(),
  Rating_Percentage = col_character(),
  X6 = col_integer(),
  X7 = col_integer(),
  X8 = col_character(),
  X9 = col_character()
)
Warning: 1 parsing failure.
row # A tibble: 1 x 5 col     row   col   expected                                                                                                       actual expected   <int> <chr>      <chr>                                                                                                        <chr> actual 1  2262    X7 an integer "Expedia Booking  availability was  , only  for  Non-  AC ; ON REQUEST  OVER  PHONE got  it.\n\nRecommended" file # ... with 1 more variables: file <chr>

# A tibble: 179,883 x 9
            Hotel_name                          Review_Title Sentiment Rating_Percentage    X6    X7    X8    X9       Word
                 <chr>                                 <chr>     <chr>             <chr> <int> <int> <chr> <chr>      <chr>
 1 Accord Metropolitan Excellent comfortableness during stay         3               100    NA    NA  <NA>  <NA>        its
 2 Accord Metropolitan Excellent comfortableness during stay         3               100    NA    NA  <NA>  <NA>     really
 3 Accord Metropolitan Excellent comfortableness during stay         3               100    NA    NA  <NA>  <NA>       Nice
 4 Accord Metropolitan Excellent comfortableness during stay         3               100    NA    NA  <NA>  <NA>      place
 5 Accord Metropolitan Excellent comfortableness during stay         3               100    NA    NA  <NA>  <NA>         to
 6 Accord Metropolitan Excellent comfortableness during stay         3               100    NA    NA  <NA>  <NA>       stay
 7 Accord Metropolitan Excellent comfortableness during stay         3               100    NA    NA  <NA>  <NA> especially
 8 Accord Metropolitan Excellent comfortableness during stay         3               100    NA    NA  <NA>  <NA>        for
 9 Accord Metropolitan Excellent comfortableness during stay         3               100    NA    NA  <NA>  <NA>   business
10 Accord Metropolitan Excellent comfortableness during stay         3               100    NA    NA  <NA>  <NA>        and
# ... with 179,873 more rows
Warning message:
Missing column names filled in: 'X6' [6], 'X7' [7], 'X8' [8], 'X9' [9] 

または

> tidytext::unnest_tokens(read.csv("chennai_reviews.csv", stringsAsFactors = FALSE), Word, Review_Text)
                                                Hotel_name
1                                      Accord Metropolitan
                                                                                                                                                                                                                                                        Review_Title
...snip...
18
Mike Stanley