Tag: r

在date时间对象上循环会产生一个数字迭代器

为什么遍历Date或POSIXct对象会导致numeric ? 例如: test = as.Date("2009-01-01") print( class( test ) ) # [1] "Date" for ( day in test ) { print( class( day ) ) } # [1] "numeric" POSIXct发生同样的情况: test = as.POSIXct("2009-01-01") print( class( test ) ) # [1] "POSIXct" "POSIXt" for ( day in test ) { print( class( day ) ) […]

比较R中的两个列表

我有两个ID列表。 我想比较这两个名单,特别是我对以下数字感兴趣: 列表A和B中有多less个ID A中有多less个ID,而B中没有 B中有多less个ID,但A中没有 我也喜欢画一个维恩图。

有什么方法可以编辑R中的函数?

假设我们有以下function: foo <- function(x) { line1 <- x line2 <- 0 line3 <- line1 + line2 return(line3) } 而我们想要改变第二行是: line2 <- 2 你会怎么做? 一种方法是使用 fix(foo) 并改变function。 另一种方法是再次写入函数。 有另一种方法吗? (请记住,任务只是改变第二行) 我想用某种方式来表示函数作为一个string(以及字符)的向量,然后改变它的一个值,然后再把它变成一个函数。

R CRAN中的注意事项检查:没有存储库集,因此跳过循环依赖关系检查

从R 3.1.0开始,我得到以下R检查: * checking package dependencies … NOTE No repository set, so cyclic dependency check skipped 我试过这个build议: https : //twitter.com/phylorich/status/431911660698083328 不行。 我把行options(repos="http://cran.rstudio.com/")放在包根目录下的.Rprofile中。 仍然得到注意。 另外编写R扩展的第1.3.1节指出: Some Windows users may need to set environment variable R_WIN_NO_JUNCTIONS to a non-empty value. The test of cyclic declarations33in DESCRIPTION files needs repositories (including CRAN) set: do this in ~/.Rprofile. 这可能是set […]

RcppArmadillo传递用户定义的函数

考虑下面的R代码, ## ———– R version ———– caller <- function(x=1:3, fun = "identity", …){ ## do some other stuff ## … ## then call the function eval(call(fun, x)) } fun1 <- function(x, …){ x + x } fun2 <- function(x, a = 10) a * x caller(fun = "fun1") caller(fun = "fun2") 用户可以传递函数名称“fun”,这是由caller使用的。 我希望用RcppArmadillo对象执行相同的任务(显然,作为更复杂任务的一部分)。 函数将在C++定义,用户通过引用其名称在R级select它: caller_cpp(1:3, […]

knitr被data.table`:=`赋值所欺骗

看起来knitr不明白DT[, a:=1]不应该导致文档的DT输出。 有没有办法阻止这种行为? 示例knitr文件: Data.Table Markdown ======================================================== Suppose we make a `data.table` in **R Markdown** “`{r} DT = data.table(a = rnorm(10)) “` Notice that it doesn't display the contents until we do a “`{r} DT “` style command. However, if we want to use `:=` to create another column “`{r} DT[, c:=5] “` It would […]

R 3.4.1“单个蜡烛”个人图书馆path错误:无法创build“不适用”

我刚刚在我的Linux Mint 18.1肉桂机上更新到R(3.4.1“Single Candle”),我试图安装一个软件包。 R返回了以下内容: > install.packages('ggplot2') Installing package into '/usr/local/lib/R/site-library' (as 'lib' is unspecified) Warning in install.packages("ggplot2") : 'lib = "/usr/local/lib/R/site-library"' is not writable Would you like to use a personal library instead? (y/n) y Would you like to create a personal library NA to install packages into? (y/n) y Error in install.packages("ggplot2") : […]

使用ggplot2绘制“序列标识”?

是否可以使用ggplot2绘制一个序列标志图 ? 有一个基于名为“ seqLogo ”的“grid”的软件包 ,但我想知道是否可以有一个ggplot2版本。 谢谢。

R CMD检查注释:未发现任何调用:'R_registerRoutines','R_useDynamicSymbols'

如何避免以下注意出现在R CMD check中的新R开发版本(R正在开发(unstable)(2017-02-15 r72179))? • checking for unstated dependencies in examples … OK • checking line endings in C/C++/Fortran sources/headers … OK • checking compiled code … NOTE File 'pkgname/libs/pkgname.so': Found no calls to: 'R_registerRoutines', 'R_useDynamicSymbols' It is good practice to register native routines and to disable symbol search. 例如在Hmisc中

为什么要定义data.table:=而不是重载< – ?

data.table引入了:=运算符。 为什么不过载< – ?