Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/64.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/search/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R中的twitteR搜索地理代码参数_R_Search_Twitter - Fatal编程技术网

R中的twitteR搜索地理代码参数

R中的twitteR搜索地理代码参数,r,search,twitter,R,Search,Twitter,我想使用twitteR进行简单的搜索,但只返回位于美国的推文。我知道twitteR有一个lat/long和lat/long范围内英里的地理编码参数,但这种定位整个国家推文的方法似乎很难 我会在这个论点中输入什么来只给我们推特呢 谢谢,我做了一个简短的搜索,看起来twitteR没有内置的国家论点。但是,由于您有lat/long,因此很容易将空间连接到美国国家/地区的形状文件(即多边形中的点) 在本例中,我使用和包spatialEco作为其point.In.polygon()函数。与其他软件包相比,

我想使用twitteR进行简单的搜索,但只返回位于美国的推文。我知道twitteR有一个lat/long和lat/long范围内英里的地理编码参数,但这种定位整个国家推文的方法似乎很难

我会在这个论点中输入什么来只给我们推特呢


谢谢,

我做了一个简短的搜索,看起来twitteR没有内置的国家论点。但是,由于您有lat/long,因此很容易将空间连接到美国国家/地区的形状文件(即多边形中的点)

在本例中,我使用和包spatialEco作为其
point.In.polygon()
函数。与其他软件包相比,它是一个非常快速的空间连接函数,即使你有几十万个坐标和几十个多边形。如果你有数百万条tweet,或者如果你以后决定加入多个多边形,例如所有世界国家,那么它可能会慢得多。但在大多数情况下,速度非常快

(另外,我没有设置twitterapi,所以我将使用一个示例数据帧,其中包含tweet_id和lat/long。)

library(maptools)#
图书馆(spatialEco)
#首先,使用setwd()将工作目录设置为名为cb_2015_us_nation_20m的文件夹

美国我做了一个简短的搜索,看起来twitteR没有内置的国家论点。但是,由于您有lat/long,因此很容易将空间连接到美国国家/地区的形状文件(即多边形中的点)

在本例中,我使用和包spatialEco作为其
point.In.polygon()
函数。与其他软件包相比,它是一个非常快速的空间连接函数,即使你有几十万个坐标和几十个多边形。如果你有数百万条tweet,或者如果你以后决定加入多个多边形,例如所有世界国家,那么它可能会慢得多。但在大多数情况下,速度非常快

(另外,我没有设置twitterapi,所以我将使用一个示例数据帧,其中包含tweet_id和lat/long。)

library(maptools)#
图书馆(spatialEco)
#首先,使用setwd()将工作目录设置为名为cb_2015_us_nation_20m的文件夹
我们
library(maptools) # to 
library(spatialEco)

# First, use setwd() to set working directory to the folder called cb_2015_us_nation_20m
us <- readShapePoly(fn = "cb_2015_us_nation_20m")
# Alternatively, you can use file.choose() and choose the .shp file like so:
us <- readShapePoly(file.choose())

# Create data frame with sample tweets
# Btw, tweet_id 1 is St. Louis, 2 is Toronto, 3 is ouston
tweets <- data.frame(tweet_id = c(1, 2, 3), 
                 latitude = c(38.610543, 43.653226, 29.760427),
                 longitude = c(-90.337189, -79.383184, -95.369803))

# Use point.in.poly to keep only tweets that are in the US
coordinates(tweets) <- ~longitude+latitude
tweets_in_us <- point.in.poly(tweets, us)
tweets_in_us <- as.data.frame(tweets_in_us)