我正在编写一个邻接矩阵R:
neighbours <- array(0, c(100,100))
for (i in 1:100) { neighbours[i,i] = 1 } #reflexive
Run Code Online (Sandbox Code Playgroud)
但后来我发现了class(neighbours)是double matrix.用更大的矩阵来占用太多空间.所以我想强迫这个类型integer,甚至更好,因为这是无向的,logical.
但...
> class(neighbours[5])
[1] "numeric"
> class(neighbours[5]) <- "integer"
> class(neighbours[5])
[1] "numeric"
Run Code Online (Sandbox Code Playgroud)
这不是听我的!
我找不到一种方法来让ggplot2在一个boxplot中显示一个空的级别,而不会将我的数据帧与实际的缺失值相混淆.这是可重现的代码:
# fake data
dftest <- expand.grid(time=1:10,measure=1:50)
dftest$value <- rnorm(dim(dftest)[1],3+0.1*dftest$time,1)
# and let's suppose we didn't observe anything at time 2
# doesn't work even when forcing with factor(..., levels=...)
p <- ggplot(data=dftest[dftest$time!=2,],aes(x=factor(time,levels=1:10),y=value))
p + geom_boxplot()
# only way seems to have at least one actual missing value in the dataframe
dftest2 <- dftest
dftest2[dftest2$time==2,"value"] <- NA
p <- ggplot(data=dftest2,aes(x=factor(time),y=value))
p + geom_boxplot()
Run Code Online (Sandbox Code Playgroud)
所以我想我错过了一些东西.在处理平衡实验时,这不是问题,因为这些缺失数据可能在数据帧中是明确的.但是,例如,在一个队列中观察到的数据,这意味着对未观察到的组合缺少值的数据进行估算...感谢您的帮助.
我正在阅读R帮助页面?devAskNewPage(它是从中链接的?par...ask).我无法理解是什么par(ask=F)/ par(ask=T)做什么.
我需要阅读以了解这一点:
If the current device is the null device, this will open a
graphics device.
...
The precise circumstances when the user will be asked to confirm a
new page depend on the graphics subsystem. Obviously this needs
to be an interactive session. In addition ‘recording’ needs to be
in operation, so only when the display list is enabled (see
‘dev.control’) which it usually is only on a screen …Run Code Online (Sandbox Code Playgroud) 假设您具有以下功能foo.当我运行一个for循环时,我希望它foo在foo最初返回值时跳过余数0.但是,break当它在函数内时不起作用.
正如它目前所写,我收到一条错误消息no loop to break from, jumping to top level.
有什么建议?
foo <- function(x) {
y <- x-2
if (y==0) {break} # how do I tell the for loop to skip this
z <- y + 100
z
}
for (i in 1:3) {
print(foo(i))
}
Run Code Online (Sandbox Code Playgroud) 我想通过这个链接证明的jQuery加载到犀牛这里.但我不断收到以下错误:
line 1086: uncaught JavaScript runtime exception: TypeError: Cannot call method "importNode" of null
Run Code Online (Sandbox Code Playgroud)
我认为jQuery无法完全加载 - 但我不知道为什么.我使用的是作者在源代码管理中发布的相同index.html文件.
这是我的Rhino控制台的跟踪:
js> load( "/temp/env.js" );
js> window.location = '/temp/index.html';
/temp/index.html
js> load( "/temp/jquery.js" );
js: "/temp/jquery.js", line 1086: uncaught JavaScript runtime exception: TypeError: Cannot call method "importNode" of null
at /temp/jquery.js:1086
at /temp/jquery.js:1079
at /temp/jquery.js:16
at <stdin>:41
Run Code Online (Sandbox Code Playgroud)
有任何想法吗?
我是R的新手.我正在编写一本关于我工作的常用功能/特性的语法的单独手册.我的示例数据框如下:
x.sample <-
structure(list(Q9_A = structure(c(5L, 3L, 5L, 3L, 5L, 3L, 1L,
5L, 5L, 5L), .Label = c("Impt", "Neutral", "Not Impt at all",
"Somewhat Impt", "Very Impt"), class = "factor"), Q9_B = structure(c(5L,
5L, 5L, 3L, 5L, 5L, 3L, 5L, 3L, 3L), .Label = c("Impt", "Neutral",
"Not Impt at all", "Somewhat Impt", "Very Impt"), class = "factor"),
Q9_C = structure(c(3L, 5L, 5L, 3L, 5L, 5L, 3L, 5L, 5L, 3L
), .Label = c("Impt", "Neutral", "Not Impt at all", "Somewhat Impt", …Run Code Online (Sandbox Code Playgroud) 如果我写
`?` <- function(a,b) (a-b)/a
Run Code Online (Sandbox Code Playgroud)
U+394只要它包含在反引号中,我就可以包括在内.(相比之下,? <- function(a,b) (a-b)/a失败了unexpected input in "?".)显然,R解析UTF-8或Unicode或类似的东西.任务进展顺利,例如评估也是如此
`?`(1:5, 9:13)
Run Code Online (Sandbox Code Playgroud)
.我也可以评估?(1:5, 9:13).
最后,如果我定义了类似的东西,winsorise <- function(x, ?=.05) { ... }那么λ(U+3bb)不需要用反引号"引入"R.然后我可以毫无问题地打电话winsorise(data, .1).
在R的文档中我唯一能提到的unicode就在我脑海中.理解它的人能否更好地向我解释 - 当R需要`理解赋值给♔时,"引擎盖下"会发生什么,但是一旦分配了can(a,b,c)就能解析?
我刚开始学习使用valgrind和--tool = memcheck
但我遇到的麻烦实际上是找到了问题.
例如
一个这样的问题是这个.
==12561== Conditional jump or move depends on uninitialised value(s)
==12561== at 0x425779: Server::HandleReceiveFrom(boost::system::error_code const&, unsigned long) (mUUID.h:63)
==12561== by 0x428EC4: boost::asio::detail::reactive_socket_recvfrom_op<boost::asio::mutable_buffers_1, boost::asio::ip::basic_endpoint<boost::asio::ip::udp>, boost::_bi::bind_t<void, boost::_mfi::mf2<void, Server, boost::system::error_code const&, unsigned long>, boost::_bi::list3<boost::_bi::value<Server*>, boost::arg<1> (*)(), boost::arg<2> (*)()> > >::do_complete(boost::asio::detail::task_io_service*, boost::asio::detail::task_io_service_operation*, boost::system::error_code, unsigned long) (mem_fn_template.hpp:280)
==12561== by 0x42E589: boost::asio::detail::task_io_service::run(boost::system::error_code&) (task_io_service_operation.hpp:35)
==12561== by 0x42720C: Server::Run() (io_service.ipp:57)
==12561== by 0x42FB00: main (obbs.cpp:198)
Run Code Online (Sandbox Code Playgroud)
另一个是这个
== Use of uninitialised value of size 8
==12561== at 0x5E56091: _itoa_word (_itoa.c:196)
==12561== by 0x5E573D8: vfprintf …Run Code Online (Sandbox Code Playgroud) 我是R的新手.我想编写一份100万字的报纸文章.所以我想写一个网络刮刀从例如监护人的网站上检索报纸上的文章:http://www.guardian.co.uk/politics/2011/oct/31/nick-clegg-investment-new-jobs.
刮刀用于从一页开始,检索文章的正文,删除所有标签并将其保存到文本文件中.然后它应该通过本页面上的链接转到下一篇文章,获取文章等,直到该文件包含大约100万字.
不幸的是,我的刮刀并没有走得太远.
我使用readLines()来访问网站的源代码,现在想要获取代码中的相关行.
Guardian中的相关部分使用此ID来标记文章的正文:
<div id="article-body-blocks">
<p>
<a href="http://www.guardian.co.uk/politics/boris"
title="More from guardian.co.uk on Boris Johnson">Boris Johnson</a>,
the...a different approach."
</p>
</div>
Run Code Online (Sandbox Code Playgroud)
我尝试使用grep和lookbehind的各种表达式来掌握这一部分 - 尝试获取此ID后面的行 - 但我认为它不适用于多行.至少我不能让它发挥作用.
有人可以帮忙吗?如果有人可以提供一些我可以继续工作的代码,那将是很棒的!
谢谢.