2016-04-23 3 views
1

データベースにデータフレームを追加しようとしていて、エラーが発生し続けると、まずこのエラーが発生しました。 tibbleパッケージをインストールした後、私は今、このエラーをデータフレーム列をリストから文字に変換すると、SQLiteエラーが発生する

> dbWriteTable(db, "Wines", Wines, row.names=FALSE, overwrite=TRUE) 
Error in (function (classes, fdef, mtable) : unable to find an inherited method for function ‘dbWriteTable’ for signature ‘"SQLiteConnection", "character", "tbl_df"’ 

を取得しています:

> dbWriteTable(db, "Wines", Wines, row.names=FALSE, overwrite=TRUE) 
Error in sqliteSendQuery(conn, statement, bind.data) : RAW() can only be applied to a 'raw', not a 'character' 

は、この問題を引き起こしている私のデータセットに何か問題はありますか?私は前にdbWriteTable()に何の問題もありませんでした。

私は問題の一部は、データフレーム内の2つの列がリストであり、変換方法がわかりません。私はunlistを試しましたが、データフレームから試したカラムを削除しました。 データはウェブスクレイピングから得られたので、ここでは私が取り組んでいることの少しです。私のデータフレームは1000行以上あります。

head(Wines) 
Source: local data frame [6 x 6] 

Winery  Name Year price rating                    excerpt 
<list> <list> <chr> <chr> <chr>                    <chr> 
1 <chr [1]> <chr [1]> 2012 140  96     Green olive, green stem and fresh herb aromas are at the fore, ... 
2 <chr [1]> <chr [1]> 2012 70  95 The kirsch, cranberry, dried herb, pomegranate and barrel spice aromas are laser ... 
3 <chr [1]> <chr [1]> 2012 70  94    Brooding dark fruit and stemmy herb and olive aromas lead to rich, ... 
4 <chr [1]> <chr [1]> 2013 20  93    This is a rare, 100% varietal Cinsault from Olsen Vineyard that saw ... 
5 <chr [1]> <chr [1]> 2012 70  93    Opening with aromas of fresh and dried herbs, this wine follows with ... 
6 <chr [1]> <chr [1]> 2013 40  93   All varietal coming from two blocks of this vineyard, this wine dazzles ... 

は、私は本当に私が文字にリストからこれらの列を変換するだけですが感じるが、一方でそれを行う方法がわからないです:私は頭を実行すると

Wines <- read.table(header = TRUE, stringsAsFactors = FALSE, text = 
"Winery Name Year Price Rating Excerpt 'Charles Smith' 'Royal City Syrah' 
'2012' '140' '96' 'Green Olive, green stem' 'K Vintners' 'Cattle King Syrah' 
'2012' '70' '95' 'cranberry, dried herb, pomegranate' 'K Vintners' 
'Klein Syrah' '2012' '70' '94' 'dark fruit, stemmy herb and olive' 
'Two Vintners' 'Make Haste Cinsault' '2013' '20' '93' '100% cinsault' 
'K Vintners' 'The Hidden Syrah' '2012' '70' '93' 'fresh and dried herbs' 
'Kerloo' 'Stone Tree Malbec' '2013' '40' '93' 'dazzles' 'Bets Family' 
'Le Parrain Cabernet Sauvignon' '2012' '135' '93' 'rare cabernet' 'Kerloo' 
'Stone Tree Vineyard Cabernet Sauvignon' '2013' '50' '93' 'high-toned herbs' 
'Effete' 'Big Papa Cabernet Sauvignon' '2012' '60' '93' 'klispun and bacchus'") 

これは私が得るものです

+0

は 'ワインは< - read.tableを(...'私のためにエラーを与えるあなたが最初の6行のdputを投稿することができますおそらく 'ワイン[1:2]。。< - lapply(ワイン[1 :2]、unlist) ' – akrun

答えて

1

これは驚くほど簡単な修正です。

Wines$Winery <- as.character(Wines$Winery) 
Wines$Name <- as.character(Wines$Name) 

これにより、指定された列のすべてがリストではなく文字に変更されました。

> head(Wines) 
Source: local data frame [6 x 6] 

     Winery     Name Year price rating 
     <chr>     <chr> <chr> <chr> <chr> 
1 Charles Smith  Royal City Syrah 2012 140  96 
2 K Vintners  Cattle King Syrah 2012 70  95 
3 K Vintners   Klein Syrah 2012 70  94 
4 Two Vintners Make Haste Cinsault 2013 20  93 
5 K Vintners  The Hidden Syrah 2012 70  93 
6  Kerloo  Stone Tree Malbec 2013 40  93 
Variables not shown: excerpt <chr>. 

これを実行すると、エラーが発生することなく正常にdbWriteTableを実行することができました。

> dbWriteTable(db, "Wines", Wines, row.names=FALSE, overwrite=TRUE) 
[1] TRUE 
関連する問題