我想使用ggplot2注释所有大于y阈值的y值.
当您plot(lm(y~x))使用基础包时,自动弹出的第二个图是Residuals vs Fitted,第三个是qqplot,第四个是Scale-location.通过将相应的X值列为相邻注释,每个值都会自动标记您的极端Y值.我正在寻找这样的东西.
使用ggplot2实现此基本默认行为的最佳方法是什么?
我正在使用R tm包,发现几乎tm_map所有删除文本元素的函数都不适用于我.
通过'工作'我的意思是,例如,我将运行:
d <- tm_map(d, removeWords, stopwords('english'))
Run Code Online (Sandbox Code Playgroud)
但是当我跑的时候
ddtm <- DocumentTermMatrix(d, control = list(
weighting = weightTfIdf,
minWordLength = 2))
findFreqTerms(ddtm, 10)
Run Code Online (Sandbox Code Playgroud)
我还是得到:
[1] the this
Run Code Online (Sandbox Code Playgroud)
等等,还有一堆其他的停用词.
我没有看到任何错误表明出现了问题.有谁知道这是什么,以及如何正确地使用停用词删除功能,或者诊断出我的错误是什么?
UPDATE
之前有一个错误,我没有抓到:
Refreshing GOE props...
---Registering Weka Editors---
Trying to add database driver (JDBC): RmiJdbc.RJDriver - Warning, not in CLASSPATH?
Trying to add database driver (JDBC): jdbc.idbDriver - Warning, not in CLASSPATH?
Trying to add database driver (JDBC): org.gjt.mm.mysql.Driver - Warning, not in CLASSPATH?
Trying to add database driver …Run Code Online (Sandbox Code Playgroud) 我喜欢使用with语句来访问文件和数据库连接,因为在发生错误或文件关闭时,它会自动为我断开连接。
f = open('file.txt', 'r')
for i in f():
print(i)
f.close()
Run Code Online (Sandbox Code Playgroud)
与
with open('file.txt', 'r') as f:
for i in f:
print(i)
Run Code Online (Sandbox Code Playgroud)
在以下情况下,是否有等效的措辞用于读取相机缓冲区?
c = cv.VideoCapture(0)
while(1):
_,f = c.read()
cv.imshow('e2',f)
if cv.waitKey(5)==27:
cv.waitKey()
break
c.release()
Run Code Online (Sandbox Code Playgroud)
我试过了:
c = cv.VideoCapture(0)
while(1):
with c.read() as _,f:
cv.imshow('e2',f)
if cv.waitKey(5)==27:
cv.waitKey()
break
Run Code Online (Sandbox Code Playgroud)
---没有运气。拆解/释放似乎是另一种功能。这是成语吗?
我有一个看起来像这样的矢量:
> vec
[1] 1 1 2 5 10
Run Code Online (Sandbox Code Playgroud)
我正试图将其转换为一种非奥林匹克排名形式,其中关系仍然是关系,但排名保持1分,即使在它之上有多个关系,所以:
> f(vec)
[1] 1 1 2 3 4
Run Code Online (Sandbox Code Playgroud)
而不是:
> rank(vec,ties.method="min")
[1] 1 1 3 4 5
Run Code Online (Sandbox Code Playgroud)
是否有功能在R中已经这样做了?我知道我可以将值转换为因子然后对因子进行排名,但这看起来有点迂回.(如果不是函数,是否有这种排名的名称?)
(乐趣:我之前没有注意到这一点,但看起来排名是幂等的,这有点酷:
> rank(vec,ties.method="min")
[1] 1 1 3 4 5
> rank(rank(vec,ties.method="min"),ties.method="min")
[1] 1 1 3 4 5
Run Code Online (Sandbox Code Playgroud)
)
我有一个 python 脚本,它对状态缩写列表作为其单个参数进行操作,还有一个包含所有状态缩写字符串的文本文件。
正常的通话是...
$ mypy.py "AK"
Run Code Online (Sandbox Code Playgroud)
...在阿拉斯加运行脚本。
我目前正在使用以下命令对从 statelist.txt 文件中获取的每个州缩写运行脚本:
$ cat statelist.txt | xargs -n 1 ./mypy.py
Run Code Online (Sandbox Code Playgroud)
我现在想要并行执行,GNU Parallels 看起来是正确的选择。我从这里看到这应该是替换的语法xargs -n1:
$ find . -name '*.html' | parallel gzip --best
Run Code Online (Sandbox Code Playgroud)
所以,我的尝试是
$ cat statelist.txt | parallel python mypy.py
Run Code Online (Sandbox Code Playgroud)
和
$ cat statelist.txt | parallel python mypy.py {}
Run Code Online (Sandbox Code Playgroud)
但这两者都正在回归:
/bin/bash: mypy.py: command not found
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'AK' is not defined
Run Code Online (Sandbox Code Playgroud)
似乎是在不加引号的情况下传递它?但是当我向“{}”添加引号时,它会传入文字“{}”。
我刚刚开始学习 Hugo 快速入门教程。
看这里,它表明我应该能够通过创建 _index.md 文件来修改 home/default/root index.html。
$ hugo new site quickstart
Congratulations! Your new Hugo site is created in ~/quickstart.
Just a few more steps and you're ready to go:
1. Download a theme into the same-named folder.
Choose a theme from https://themes.gohugo.io/, or
create your own with the "hugo new theme <THEMENAME>" command.
2. Perhaps you want to add some content. You can add single files
with "hugo new <SECTIONNAME>/<FILENAME>.<FORMAT>".
3. Start the built-in live …Run Code Online (Sandbox Code Playgroud) 在Python中,我有以下内容:
i = series.index(s) # standard Python list.index() function
tmp = series.pop(i)
blah = f(tmp)
series.append(tmp)
Run Code Online (Sandbox Code Playgroud)
在将其转换为Go时,我正在寻找一种类似的方法,通过索引从切片中检索项目,对其执行某些操作,然后将原始项目放在切片的末尾.
从这里开始,我得出以下结论:
i = Index(series, s) // my custom index function...
tmp, series = series[i], series[i+1:]
blah := f(tmp)
series = append(series, tmp)
Run Code Online (Sandbox Code Playgroud)
但是这在列表末尾失败了:
panic: runtime error: slice bounds out of range
Run Code Online (Sandbox Code Playgroud)
我怎么会习惯性地把它翻译slice.pop()成Go?
我正在使用junk.hs文件加载ghci.我没有使用我的main函数,只是调用文件中的其他函数来测试它们,例如:
-- junk.hs
main :: IO ()
main = putStrLn "hello"
otherFunction a b = a + b
Run Code Online (Sandbox Code Playgroud)
当我加载:
Prelude> :l junk.hs
Prelude> otherFunction 1 2 -- good
Run Code Online (Sandbox Code Playgroud)
这很好,因为我不是主要的,因为我必须定义一些主要功能,这就完成了工作.
但是,什么是正确的最小,null主函数?
我试过了
main :: IO ()
main = Nothing
Run Code Online (Sandbox Code Playgroud)
而这失败了
*Main> :load junk.hs
[1 of 1] Compiling Main ( junk.hs, interpreted )
junk.hs:2:8: error:
• Couldn't match expected type ‘IO ()’ with actual type ‘Maybe a0’
• In the expression: Nothing
In an equation for ‘main’: main = Nothing
|
2 …Run Code Online (Sandbox Code Playgroud) 我正在查看这个问题,了解如何获取多个列表并将它们转换为列表列表。我有以下几点:
Prelude> x1 = [1,2,3]
Prelude> x2 = [4,5,6]
Prelude> x3 = [7,8,9]
Run Code Online (Sandbox Code Playgroud)
我想看到一些 \function 这可能是可变参数:
Prelude> xs = map (\function -> ???) x1 x2 x3
Prelude> show xs -- that produces this
[[1,2,3], [4,5,6], [7,8,9]]
Run Code Online (Sandbox Code Playgroud)
或者没有映射,其他一些可变参数函数 F 使得:
Prelude> xs = F x1 x2 x3 ... x1000
Prelude> show xs -- that produces this
[[1,2,3], [4,5,6], [7,8,9], ...., [1000000,1000001,1000002]]
Run Code Online (Sandbox Code Playgroud)
我对答案的期望是类似
Prelude> map (:) x1 x2 x3 []
<interactive>:26:1: error:
• Couldn't match expected type ‘[Integer]
-> [Integer] …Run Code Online (Sandbox Code Playgroud) 我理解 R 中重复事物的答案通常是“ apply()”而不是循环。对于我经常创建的一些讨厌的代码,是否有更好的 R 设计模式?
因此,从 HTML 中提取表格数据,我通常需要更改数据类型,并最终运行这样的东西,将第一列转换为日期格式(从十进制),并将第 2-4 列从带有逗号千位分隔符的字符串转换为比如“2,400,000”到数字“2400000”。
X[,1] <- decYY2YY(as.numeric(X[,1]))
X[,2] <- as.numeric(gsub(",", "", X[,2]))
X[,3] <- as.numeric(gsub(",", "", X[,3]))
X[,4] <- as.numeric(gsub(",", "", X[,4]))
Run Code Online (Sandbox Code Playgroud)
我不喜欢在这里的左侧和骑行侧都有 X[,number] 重复,或者我对 2-4 重复了基本相同的语句。
是否有一种非常 R 风格的方法可以使 X[,2] 减少重复但仍然无循环?某种说法是“将其应用于第 2、3、4 列——一个将当前列重新分配给适当修改版本的函数?”
我不想创建一个完整的、可重复的清洁功能,真的,只是一个快速的匿名功能,可以减少重复。
r ×4
go ×2
haskell ×2
python ×2
annotations ×1
apply ×1
bash ×1
coding-style ×1
ggplot2 ×1
hugo ×1
list ×1
nlp ×1
opencv ×1
ranking ×1
slice ×1
static-site ×1
stop-words ×1
tm ×1
xargs ×1