R新手在这里我有看起来像这样的数据:
{'id': 19847005, 'profile_sidebar_fill_color': u'http://pbs.foo.com/profile_background', 'profile_text_color': u'333333', 'followers_count': 1105, 'location': u'San Diego, CA', 'profile_background_color': u'9AE4E8', 'listed_count': 43, '009', 'time_zone': u'Pacific Time (US & Canada)', 'protected': False}
我想从此文本中提取位置数据:加利福尼亚州圣地亚哥。
我一直在尝试使用这个 stringr 包来实现这一点,但不能完全获得正则表达式来捕获城市和州。有时状态会存在,有时不存在。
location_pattern <- "'location':\su'(\w+)'"
rawdata$location <- str_extract(rawdata$user, location_pattern)