2016-07-03 10 views
0

JSONファイル(ストリーミングAPIを使用したツイートのキャプチャです.50.000のレジスタがあります)を変換しようとしています。この文字「/ n」のために不可能です。 (例を見て:http://imgur.com/ymxCrmk) 私はデータを視覚化しようとするたびに、/ nのために改行があり、私は自分のデータを扱うことができません... 私は可能性を持っていますここで私は誰もが、私を助けてくださいすることができますつぶやきJSON Excelに変換

setwd(); 
file <- "myfile.json" 
# as json object 
mytweets<-readTweets("myfile") 
# as dataframe 
tweets.df <- parseTweets("myfile", simplify = FALSE) 

を使用するコードがある...すべての情報をクリアすることによって、容易

を私のデータをフィルタリングします?

+3

代わりに画像のは、あなたが直接質問に(私は仮定)myfile.jsonの内容を追加することができますか?システムがあなたを許さない場合は、[Pastebin](https://pastebin.com)を使用することもできます。 – grooveplex

+0

こんにちは、ごめんなさい、JSONデータとのリンクがあります: https://dl.dropboxusercontent.com/u/389103/egyptair.json.gz 私はこの質問に追加する必要があります。私はInfogr.amを使用してチャートを作成しなければならないので、私はデータをExcelファイルに変換したいと思っています。私はデータをより明確にする必要があります。ありがとうございます。 –

+1

readTweetsで宣言しているときに "myfile"ではなく "file"(引用符なし)にする必要はありませんか? –

答えて

2
write.csv2(df, tf <- tempfile(fileext = ".csv"), row.names = F) 
shell.exec(tf) # open file on windows machine, where .csv is associated with excel 

私のために正常に動作します:

enter image description here

ヘルプ?write.csv2

write.csv2は、小数点と セパレータセミコロン、カンマを使用していますと言いますいくつかの西ヨーロッパの ロケールのCSVファイルのExcelコンベンション。

これは私の場合に当てはまります。それを調整する必要があるかもしれません。 \t(タブ)または,(カンマ)のような別の区切り文字を使用するか、Excelで既定の区切り文字を変更してください。

もう1つの方法は、すべての改行をあらかじめ交換することです。gsub("\n", "", df$text)

データ...

... dput(head(tweets.df, 3))

df <- structure(list(text = c("RT @louane: Oui @Solidays sera la prochaine date à Paris ! \nmais d'abord @Zenith_Paris ce soir et demain encore !! <ed><U+00A0><U+00BD><ed><U+00B4><U+00A5><ed><U+00A0><U+00BD><ed><U+00B2><U+00A5> https://.../Pf8yNp56…", 
"EgyptAir Jet Disappears Over Mediterranean Sea https://.../SW2yWp6RrG https://.../0xeWSBZlvI", 
"RT @morandiniblog: EN DIRECT - Paris et Le Caire expriment \"leurs condoléances\" aux familles des victimes du crash du vol MS804 https://t.c…" 
), retweet_count = c(25, 0, 4), favorited = c(FALSE, FALSE, FALSE 
), truncated = c(FALSE, FALSE, FALSE), id_str = c("733225923248566272", 
"733225923621867520", "733225924385247232"), in_reply_to_screen_name = c(NA_character_, 
NA_character_, NA_character_), source = c("<a href=\"http://twitter.com/download/android\" rel=\"nofollow\">Twitter for Android</a>", 
"<a href=\"http://twitter.com/download/iphone\" rel=\"nofollow\">Twitter for iPhone</a>", 
"<a href=\"http://twitter.com\" rel=\"nofollow\">Twitter Web Client</a>" 
), retweeted = c(FALSE, FALSE, FALSE), created_at = c("Thu May 19 09:20:57 +0000 2016", 
"Thu May 19 09:20:57 +0000 2016", "Thu May 19 09:20:57 +0000 2016" 
), in_reply_to_status_id_str = c(NA_character_, NA_character_, 
NA_character_), in_reply_to_user_id_str = c(NA_character_, NA_character_, 
NA_character_), lang = c("fr", "en", "fr"), listed_count = c(33, 
0, 1), verified = c(FALSE, FALSE, FALSE), location = c("Udine ITALY", 
"Instagram: dimple_90s", "Bordeaux "), user_id_str = c("2703557176", 
"2169023166", "865179050"), description = c("NEW VIDEO,NEWS,CHARTS,SPORTS,\nFASHION,ONLY OFFICIAL PAGES..", 
"20. Watford/3rd Year UoW.", "je veux désormais conserver que les moments de bonheur <U+2728>    communication - Bordeaux" 
), geo_enabled = c(TRUE, TRUE, TRUE), user_created_at = c("Sat Jul 12 15:06:22 +0000 2014", 
"Fri Nov 01 20:16:38 +0000 2013", "Sat Oct 06 19:23:29 +0000 2012" 
), statuses_count = c(11283, 7481, 20834), followers_count = c(1909, 
305, 140), favourites_count = c(155920, 2413, 2019), protected = c(FALSE, 
FALSE, FALSE), user_url = c(NA_character_, NA_character_, NA_character_ 
), name = c("MUSIC news!", "George The Mermaid<U+264A><U+FE0F>", 
"Laura"), time_zone = c(NA, NA, "Paris"), user_lang = c("it", 
"en", "fr"), utc_offset = c(NA, NA, 7200), friends_count = c(354, 
278, 329), screen_name = c("barreca51", "GeorgiaWalker95", "laulylove" 
), country_code = c(NA_character_, NA_character_, NA_character_ 
), country = c(NA_character_, NA_character_, NA_character_), 
    place_type = c(NA_character_, NA_character_, NA_character_ 
    ), full_name = c(NA_character_, NA_character_, NA_character_ 
    ), place_name = c(NA, NA, NA), place_id = c(NA, NA, NA), 
    place_lat = c(NaN, NaN, NaN), place_lon = c(NaN, NaN, NaN 
    ), lat = c(NA_real_, NA_real_, NA_real_), lon = c(NA_real_, 
    NA_real_, NA_real_), expanded_url = c("https://twitter.com/justemoi2013/status/733173507023069184", 
    "http://news.sky.com/story/1698511/egyptair-jet-disappears-over-mediterranean-sea", 
    "http://www.jeanmarcmorandini.com/article-353767-en-direct-disparition-du-vol-paris-le-caire-l-avion-s-est-ecrase-au-large-de-l-ile-grecque-de-karpathos-dans-l-espace-aerien-egyptien.html" 
    ), url = c("https://.../Pf8yNp56Th", "https://.../SW2yWp6RrG", 
    "https://.../hok65e82pV")), .Names = c("text", "retweet_count", 
"favorited", "truncated", "id_str", "in_reply_to_screen_name", 
"source", "retweeted", "created_at", "in_reply_to_status_id_str", 
"in_reply_to_user_id_str", "lang", "listed_count", "verified", 
"location", "user_id_str", "description", "geo_enabled", "user_created_at", 
"statuses_count", "followers_count", "favourites_count", "protected", 
"user_url", "name", "time_zone", "user_lang", "utc_offset", "friends_count", 
"screen_name", "country_code", "country", "place_type", "full_name", 
"place_name", "place_id", "place_lat", "place_lon", "lat", "lon", 
"expanded_url", "url"), row.names = c(NA, 3L), class = "data.frame") 
+0

は完璧です!ありがとう@lukeA :) –