我希望能够跟踪包含某组词的推文,而不是其他推文.例如,如果我的过滤器是:"taco"AND("鸡"或"牛肉").
它应该返回这些推文:
-I am eating a chicken taco.
-I am eating a beef taco.
Run Code Online (Sandbox Code Playgroud)
它不应该返回这些推文:
-I am eating a taco.
-I am eating a pork taco.
Run Code Online (Sandbox Code Playgroud)
这是我目前正在运行的代码:
from tweepy import Stream
from tweepy import OAuthHandler
from tweepy.streaming import StreamListener
import time
import json
# authentication data- get this info from twitter after you create your application
ckey = '...' # consumer key, AKA API key
csecret = '...' # consumer secret, AKA API secret
atoken = '...' # access token …Run Code Online (Sandbox Code Playgroud) 我希望创建一个包含两个不同值的向量的所有可能排列,在其中我控制每个值的比例。
例如,如果我有一个长度为三的向量,并且我希望所有可能的组合都包含一个单一的1,那么我想要的输出就是一个看起来像这样的列表:
list.1 <- list(c(1,0,0), c(0,1,0), c(0,0,1))
Run Code Online (Sandbox Code Playgroud)
相反,如果我希望所有可能的组合包含三个1,那么我想要的输出是一个看起来像这样的列表:
list.3 <- list(c(1,1,1))
Run Code Online (Sandbox Code Playgroud)
换一种方式,格局1和0物质价值,但所有1S的关系被视为等同于其他所有1秒。
基于此处和其他位置的搜索,我尝试了几种方法:
expand.grid(0:1, 0:1, 0:1) # this includes all possible combinations of 1, 2, or 3 ones
permn(c(0,1,1)) # this does not treat the ones as identical (e.g. it produces (0,1,1) twice)
unique(permn(c(0,1,1))) # this does the job!
Run Code Online (Sandbox Code Playgroud)
因此,使用permn软件包中的功能combinat似乎很有希望。但是,在将其扩展到我的实际问题(长度为20的矢量,具有50%1s和50%0s的位置)时,我遇到了问题:
unique(permn(c(rep(1,10), rep(0, 10))))
# returns the error:
Error in vector("list", gamma(n + 1)) :
vector size specified is …Run Code Online (Sandbox Code Playgroud) 我有一些时间序列的数据,其中观察到一些数据并且模拟了一些数据.我想生成一个随时间变化的整个数据系列图,颜色表示数据源.但是,我只能弄清楚如何在同一组中的ggplot连接点中制作geom_line().
这是一个澄清的例子:
# Create sample data
df <- data.frame(cbind(seq(1,9,1), c(1,2,3,4,5,4,3,2,1), c("obs","obs", "obs", "obs", "sim","sim","obs","sim", "obs")))
colnames(df) <- c("time", "value", "source")
# Make a plot
p <- ggplot(df, aes(x=time, y=value, group=source, color=source))
p + geom_point() # shows all the points in sequential order as dots
p + geom_point() + geom_line() # connects obs to obs and sim to sim
Run Code Online (Sandbox Code Playgroud)
在这个例子中,我希望一条线在x轴上从1:9顺序排列,连接所有点,但是根据组改变线条(和点)的颜色.
我正在尝试将ESRI网格绘制为曲面的光栅图像.我已经弄清楚如何制作情节,但不知道如何控制R的色阶.
# open necessary libraries
library("raster")
library("rgdal")
library("ncdf")
# goal: select an ESRI Grid ASCII file and plot it as an image.
infile <- file.choose("Results")
r <- raster(infile)
# read in metadata from ESRI output file, split up into relevant variables
info <- read.table(infile, nrows=6)
NCOLS <- info[1,2]
NROWS <- info[2,2]
XLLCORNER <- info[3,2]
YLLCORNER <- info[4,2]
CELLSIZE <- info[5,2]
NODATA_VALUE <- info[6,2]
XURCORNER <- XLLCORNER+(NCOLS-1)*CELLSIZE
YURCORNER <- YLLCORNER+(NROWS-1)*CELLSIZE
# plot output data - whole model domain
pal <- colorRampPalette(c("purple","blue","cyan","green","yellow","red")) …Run Code Online (Sandbox Code Playgroud)