我对R编程完全不熟悉。 试着靠自己学习。 我有一个场景,我有一堆推文。 我想基于单词来过滤这些推文,如果它在推文文本中退出,那么它应该得到所有的推文以及它的其他属性。
sample.json
{"created_at":"Wed Oct 12 06:33:06 +0000 2016","id":786092312011112448,"id_str":"786092312011112448","text":"I posted a new photo to Google https:\/\/t.co\/5SBpo628DF","source":"\u003ca href=\"http:\/\/www.facebook.com\/twitter\" rel=\"nofollow\"\u003eFacebook\u003c\/a\u003e","truncated":false,"in_reply_to_status_id":null,"in_reply_to_status_id_str":null,"in_reply_to_user_id":null,"in_reply_to_user_id_str":null,"in_reply_to_screen_name":null,"user":{"id":359430735,"id_str":"359430735","name":"Life Changing Quotes","screen_name":"dadhwalashish","location":"Jalandhar India","url":"http:\/\/www.CompassionKindness.com","description":"@armyofkind , Human Resources professional, Blogger, Happiness ambassador, Kindness warrior, Love agent, Humanity over all religion.","protected":false,"verified":false,"followers_count":1919,"friends_count":1973,"listed_count":41,"favourites_count":24456,"statuses_count":20738,"created_at":"Sun Aug 21 15:39:19 +0000 2011","utc_offset":19800,"time_zone":"New Delhi","geo_enabled":false,"lang":"en","contributors_enabled":false,"is_translator":false,"profile_background_color":"C0DEED","profile_background_image_url":"http:\/\/abs.twimg.com\/images\/themes\/theme1\/bg.png","profile_background_image_url_https":"https:\/\/abs.twimg.com\/images\/themes\/theme1\/bg.png","profile_background_tile":false,"profile_link_color":"0084B4","profile_sidebar_border_color":"C0DEED","profile_sidebar_fill_color":"DDEEF6","profile_text_color":"333333","profile_use_background_image":true,"profile_image_url":"http:\/\/pbs.twimg.com\/profile_images\/759986435453837312\/26b_K_9u_normal.jpg","profile_image_url_https":"https:\/\/pbs.twimg.com\/profile_images\/759986435453837312\/26b_K_9u_normal.jpg","profile_banner_url":"https:\/\/pbs.twimg.com\/profile_banners\/359430735\/1472921460","default_profile":true,"default_profile_image":false,"following":null,"follow_request_sent":null,"notifications":null},"geo":null,"coordinates":null,"place":null,"contributors":null,"is_quote_status":false,"retweet_count":0,"favorite_count":0,"entities":{"hashtags":[],"urls":[{"url":"https:\/\/t.co\/5SBpo628DF","expanded_url":"http:\/\/fb.me\/1nqsSEAnu","display_url":"fb.me\/1nqsSEAnu","indices":[33,56]}],"user_mentions":[],"symbols":[]},"favorited":false,"retweeted":false,"possibly_sensitive":false,"filter_level":"low","lang":"en","timestamp_ms":"1476253986729"}
{"created_at":"Wed Oct 12 06:33:06 +0000 2016","id":786092312011112448,"id_str":"786092312011112448","text":"I posted a new photo to Google https:\/\/t.co\/5SBpo628DF","source":"\u003ca href=\"http:\/\/www.facebook.com\/twitter\" rel=\"nofollow\"\u003eFacebook\u003c\/a\u003e","truncated":false,"in_reply_to_status_id":null,"in_reply_to_status_id_str":null,"in_reply_to_user_id":null,"in_reply_to_user_id_str":null,"in_reply_to_screen_name":null,"user":{"id":359430735,"id_str":"359430735","name":"Life Changing Quotes","screen_name":"dadhwalashish","location":"Jalandhar India","url":"http:\/\/www.CompassionKindness.com","description":"@armyofkind , Human Resources professional, Blogger, Happiness ambassador, Kindness warrior, Love agent, Humanity over all religion.","protected":false,"verified":false,"followers_count":1919,"friends_count":1973,"listed_count":41,"favourites_count":24456,"statuses_count":20738,"created_at":"Sun Aug 21 15:39:19 +0000 2011","utc_offset":19800,"time_zone":"New Delhi","geo_enabled":false,"lang":"en","contributors_enabled":false,"is_translator":false,"profile_background_color":"C0DEED","profile_background_image_url":"http:\/\/abs.twimg.com\/images\/themes\/theme1\/bg.png","profile_background_image_url_https":"https:\/\/abs.twimg.com\/images\/themes\/theme1\/bg.png","profile_background_tile":false,"profile_link_color":"0084B4","profile_sidebar_border_color":"C0DEED","profile_sidebar_fill_color":"DDEEF6","profile_text_color":"333333","profile_use_background_image":true,"profile_image_url":"http:\/\/pbs.twimg.com\/profile_images\/759986435453837312\/26b_K_9u_normal.jpg","profile_image_url_https":"https:\/\/pbs.twimg.com\/profile_images\/759986435453837312\/26b_K_9u_normal.jpg","profile_banner_url":"https:\/\/pbs.twimg.com\/profile_banners\/359430735\/1472921460","default_profile":true,"default_profile_image":false,"following":null,"follow_request_sent":null,"notifications":null},"geo":null,"coordinates":null,"place":null,"contributors":null,"is_quote_status":false,"retweet_count":0,"favorite_count":0,"entities":{"hashtags":[],"urls":[{"url":"https:\/\/t.co\/5SBpo628DF","expanded_url":"http:\/\/fb.me\/1nqsSEAnu","display_url":"fb.me\/1nqsSEAnu","indices":[33,56]}],"user_mentions":[],"symbols":[]},"favorited":false,"retweeted":false,"possibly_sensitive":false,"filter_level":"low","lang":"en","timestamp_ms":"1476253986729"}{"created_at":"Wed Oct 12 06:33:06 +0000 2016","id":786092312011112448,"id_str":"786092312011112448","text":"I posted a new photo to Facebook https:\/\/t.co\/5SBpo628DF","source":"\u003ca href=\"http:\/\/www.facebook.com\/twitter\" rel=\"nofollow\"\u003eFacebook\u003c\/a\u003e","truncated":false,"in_reply_to_status_id":null,"in_reply_to_status_id_str":null,"in_reply_to_user_id":null,"in_reply_to_user_id_str":null,"in_reply_to_screen_name":null,"user":{"id":359430735,"id_str":"359430735","name":"Life Changing Quotes","screen_name":"dadhwalashish","location":"Jalandhar India","url":"http:\/\/www.CompassionKindness.com","description":"@armyofkind , Human Resources professional, Blogger, Happiness ambassador, Kindness warrior, Love agent, Humanity over all religion.","protected":false,"verified":false,"followers_count":1919,"friends_count":1973,"listed_count":41,"favourites_count":24456,"statuses_count":20738,"created_at":"Sun Aug 21 15:39:19 +0000 2011","utc_offset":19800,"time_zone":"New Delhi","geo_enabled":false,"lang":"en","contributors_enabled":false,"is_translator":false,"profile_background_color":"C0DEED","profile_background_image_url":"http:\/\/abs.twimg.com\/images\/themes\/theme1\/bg.png","profile_background_image_url_https":"https:\/\/abs.twimg.com\/images\/themes\/theme1\/bg.png","profile_background_tile":false,"profile_link_color":"0084B4","profile_sidebar_border_color":"C0DEED","profile_sidebar_fill_color":"DDEEF6","profile_text_color":"333333","profile_use_background_image":true,"profile_image_url":"http:\/\/pbs.twimg.com\/profile_images\/759986435453837312\/26b_K_9u_normal.jpg","profile_image_url_https":"https:\/\/pbs.twimg.com\/profile_images\/759986435453837312\/26b_K_9u_normal.jpg","profile_banner_url":"https:\/\/pbs.twimg.com\/profile_banners\/359430735\/1472921460","default_profile":true,"default_profile_image":false,"following":null,"follow_request_sent":null,"notifications":null},"geo":null,"coordinates":null,"place":null,"contributors":null,"is_quote_status":false,"retweet_count":0,"favorite_count":0,"entities":{"hashtags":[],"urls":[{"url":"https:\/\/t.co\/5SBpo628DF","expanded_url":"http:\/\/fb.me\/1nqsSEAnu","display_url":"fb.me\/1nqsSEAnu","indices":[33,56]}],"user_mentions":[],"symbols":[]},"favorited":false,"retweeted":false,"possibly_sensitive":false,"filter_level":"low","lang":"en","timestamp_ms":"1476253986729"}
{"created_at":"Wed Oct 12 06:33:06 +0000 2016","id":786092312011112448,"id_str":"786092312011112448","text":"I posted a new photo to Google https:\/\/t.co\/5SBpo628DF","source":"\u003ca href=\"http:\/\/www.facebook.com\/twitter\" rel=\"nofollow\"\u003eFacebook\u003c\/a\u003e","truncated":false,"in_reply_to_status_id":null,"in_reply_to_status_id_str":null,"in_reply_to_user_id":null,"in_reply_to_user_id_str":null,"in_reply_to_screen_name":null,"user":{"id":359430735,"id_str":"359430735","name":"Life Changing Quotes","screen_name":"dadhwalashish","location":"Jalandhar India","url":"http:\/\/www.CompassionKindness.com","description":"@armyofkind , Human Resources professional, Blogger, Happiness ambassador, Kindness warrior, Love agent, Humanity over all religion.","protected":false,"verified":false,"followers_count":1919,"friends_count":1973,"listed_count":41,"favourites_count":24456,"statuses_count":20738,"created_at":"Sun Aug 21 15:39:19 +0000 2011","utc_offset":19800,"time_zone":"New Delhi","geo_enabled":false,"lang":"en","contributors_enabled":false,"is_translator":false,"profile_background_color":"C0DEED","profile_background_image_url":"http:\/\/abs.twimg.com\/images\/themes\/theme1\/bg.png","profile_background_image_url_https":"https:\/\/abs.twimg.com\/images\/themes\/theme1\/bg.png","profile_background_tile":false,"profile_link_color":"0084B4","profile_sidebar_border_color":"C0DEED","profile_sidebar_fill_color":"DDEEF6","profile_text_color":"333333","profile_use_background_image":true,"profile_image_url":"http:\/\/pbs.twimg.com\/profile_images\/759986435453837312\/26b_K_9u_normal.jpg","profile_image_url_https":"https:\/\/pbs.twimg.com\/profile_images\/759986435453837312\/26b_K_9u_normal.jpg","profile_banner_url":"https:\/\/pbs.twimg.com\/profile_banners\/359430735\/1472921460","default_profile":true,"default_profile_image":false,"following":null,"follow_request_sent":null,"notifications":null},"geo":null,"coordinates":null,"place":null,"contributors":null,"is_quote_status":false,"retweet_count":0,"favorite_count":0,"entities":{"hashtags":[],"urls":[{"url":"https:\/\/t.co\/5SBpo628DF","expanded_url":"http:\/\/fb.me\/1nqsSEAnu","display_url":"fb.me\/1nqsSEAnu","indices":[33,56]}],"user_mentions":[],"symbols":[]},"favorited":false,"retweeted":false,"possibly_sensitive":false,"filter_level":"low","lang":"en","timestamp_ms":"1476253986729"}{"created_at":"Wed Oct 12 06:33:06 +0000 2016","id":786092312011112448,"id_str":"786092312011112448","text":"I posted a new photo to Google https:\/\/t.co\/5SBpo628DF","source":"\u003ca href=\"http:\/\/www.facebook.com\/twitter\" rel=\"nofollow\"\u003eFacebook\u003c\/a\u003e","truncated":false,"in_reply_to_status_id":null,"in_reply_to_status_id_str":null,"in_reply_to_user_id":null,"in_reply_to_user_id_str":null,"in_reply_to_screen_name":null,"user":{"id":359430735,"id_str":"359430735","name":"Life Changing Quotes","screen_name":"dadhwalashish","location":"Jalandhar India","url":"http:\/\/www.CompassionKindness.com","description":"@armyofkind , Human Resources professional, Blogger, Happiness ambassador, Kindness warrior, Love agent, Humanity over all religion.","protected":false,"verified":false,"followers_count":1919,"friends_count":1973,"listed_count":41,"favourites_count":24456,"statuses_count":20738,"created_at":"Sun Aug 21 15:39:19 +0000 2011","utc_offset":19800,"time_zone":"New Delhi","geo_enabled":false,"lang":"en","contributors_enabled":false,"is_translator":false,"profile_background_color":"C0DEED","profile_background_image_url":"http:\/\/abs.twimg.com\/images\/themes\/theme1\/bg.png","profile_background_image_url_https":"https:\/\/abs.twimg.com\/images\/themes\/theme1\/bg.png","profile_background_tile":false,"profile_link_color":"0084B4","profile_sidebar_border_color":"C0DEED","profile_sidebar_fill_color":"DDEEF6","profile_text_color":"333333","profile_use_background_image":true,"profile_image_url":"http:\/\/pbs.twimg.com\/profile_images\/759986435453837312\/26b_K_9u_normal.jpg","profile_image_url_https":"https:\/\/pbs.twimg.com\/profile_images\/759986435453837312\/26b_K_9u_normal.jpg","profile_banner_url":"https:\/\/pbs.twimg.com\/profile_banners\/359430735\/1472921460","default_profile":true,"default_profile_image":false,"following":null,"follow_request_sent":null,"notifications":null},"geo":null,"coordinates":null,"place":null,"contributors":null,"is_quote_status":false,"retweet_count":0,"favorite_count":0,"entities":{"hashtags":[],"urls":[{"url":"https:\/\/t.co\/5SBpo628DF","expanded_url":"http:\/\/fb.me\/1nqsSEAnu","display_url":"fb.me\/1nqsSEAnu","indices":[33,56]}],"user_mentions":[],"symbols":[]},"favorited":false,"retweeted":false,"possibly_sensitive":false,"filter_level":"low","lang":"en","timestamp_ms":"1476253986729"}
{"created_at":"Wed Oct 12 06:33:06 +0000 2016","id":786092312011112448,"id_str":"786092312011112448","text":"I posted a new photo to Twiiter https:\/\/t.co\/5SBpo628DF","source":"\u003ca href=\"http:\/\/www.facebook.com\/twitter\" rel=\"nofollow\"\u003eFacebook\u003c\/a\u003e","truncated":false,"in_reply_to_status_id":null,"in_reply_to_status_id_str":null,"in_reply_to_user_id":null,"in_reply_to_user_id_str":null,"in_reply_to_screen_name":null,"user":{"id":359430735,"id_str":"359430735","name":"Life Changing Quotes","screen_name":"dadhwalashish","location":"Jalandhar India","url":"http:\/\/www.CompassionKindness.com","description":"@armyofkind , Human Resources professional, Blogger, Happiness ambassador, Kindness warrior, Love agent, Humanity over all religion.","protected":false,"verified":false,"followers_count":1919,"friends_count":1973,"listed_count":41,"favourites_count":24456,"statuses_count":20738,"created_at":"Sun Aug 21 15:39:19 +0000 2011","utc_offset":19800,"time_zone":"New Delhi","geo_enabled":false,"lang":"en","contributors_enabled":false,"is_translator":false,"profile_background_color":"C0DEED","profile_background_image_url":"http:\/\/abs.twimg.com\/images\/themes\/theme1\/bg.png","profile_background_image_url_https":"https:\/\/abs.twimg.com\/images\/themes\/theme1\/bg.png","profile_background_tile":false,"profile_link_color":"0084B4","profile_sidebar_border_color":"C0DEED","profile_sidebar_fill_color":"DDEEF6","profile_text_color":"333333","profile_use_background_image":true,"profile_image_url":"http:\/\/pbs.twimg.com\/profile_images\/759986435453837312\/26b_K_9u_normal.jpg","profile_image_url_https":"https:\/\/pbs.twimg.com\/profile_images\/759986435453837312\/26b_K_9u_normal.jpg","profile_banner_url":"https:\/\/pbs.twimg.com\/profile_banners\/359430735\/1472921460","default_profile":true,"default_profile_image":false,"following":null,"follow_request_sent":null,"notifications":null},"geo":null,"coordinates":null,"place":null,"contributors":null,"is_quote_status":false,"retweet_count":0,"favorite_count":0,"entities":{"hashtags":[],"urls":[{"url":"https:\/\/t.co\/5SBpo628DF","expanded_url":"http:\/\/fb.me\/1nqsSEAnu","display_url":"fb.me\/1nqsSEAnu","indices":[33,56]}],"user_mentions":[],"symbols":[]},"favorited":false,"retweeted":false,"possibly_sensitive":false,"filter_level":"low","lang":"en","timestamp_ms":"1476253986729"}
Words.txt
google
facebook
twitter
如果推特中存在谷歌词:文本,那么它应该获得该词所包含的所有推文,并且与其他词相同。 我正在尝试自己,但需要一些专家。 最好的方法是什么。请告诉我任何参考资料和书籍或文件。
提前致谢。 Mohan.V
答案 0 :(得分:0)
你可以从这样的事情开始:
# words to match
words <- c("google","facebook","twitter")
# sample words. put real jsons here
sample.jsons <- c("google","twitch","twitter","twitch","facebook","twitch","google","facebook","twitter")
# run through all jsons and target words
for(i in seq_along(sample.jsons)){
for(j in seq_along(words)){
# if this condition is TRUE, your criteria is fullfilled
if(words[[j]] %in% sample.jsons[[i]]){
# do whatever you want with the jsons which match your criteria
# right now the following command just outputs all index values at which the criteria is fulfilled
print(i)
}
}
}
但是,我强烈建议您(a)在继续之前先看看SO指南和规则,以及(b)R编程的基础知识。如果你不这样做,你很可能马上遇到下一个问题。
好的开始是: