R: Is there any performance difference between using = or <

This question already has an answer here: What are the differences between “=” and “<-” in R? 6 answers No measurable performance difference; more about readability and convention. It's all the computations that R is doing that will make or break you. Use <- ; "R In Action" says on page 7 that it's standard and other R developers will make fun of you if you don&#

R:使用=还是<性能差异?

这个问题在这里已经有了答案: R中“=”和“< - ”之间有什么区别? 6个答案 没有可测量的性能差异; 更多关于可读性和约定。 R所做的所有计算都会造成或破坏你。 使用<- ; “R In Action”在第7页上说,它是标准的,如果你不这样做,其他R开发者会嘲笑你。 R文档中可能有更深层的原因: 有三种不同的赋值操作符:其中两个有向左和向右的形式。 运算符< - 和=分配到它们被评估的环境中。 运算符< - 可以

"x" and 'x' , x <

This question already has an answer here: What are the differences between “=” and “<-” in R? 6 answers In your examples, the answer is yes. But see notes below: https://stat.ethz.ch/R-manual/R-devel/library/base/html/Quotes.html Single and double quotes delimit character constants. They can be used interchangeably but double quotes are preferred (and character constants are printed

“x”和“x”,x <

这个问题在这里已经有了答案: R中“=”和“< - ”之间有什么区别? 6个答案 在你的例子中,答案是肯定的。 但请参阅下面的注释: https://stat.ethz.ch/R-manual/R-devel/library/base/html/Quotes.html 单引号和双引号分隔字符常量。 它们可以互换使用,但双引号是首选(字符常量使用双引号打印),所以单引号通常仅用于分隔包含双引号的字符常量。 http://blog.revolutionanalytics.com/2008/12/use-equals-or-ar

The different ways of declaring objects in R

This question already has an answer here: What are the differences between “=” and “<-” in R? 6 answers In some sense = and <- are equivalent, but the latter is preferred because = is also overwritten to specify default arguments (where <- will not work). As for <<- , it is trickier and not recommended. In R, every step of execution along arbitrary code will be associated w

在R中声明对象的不同方式

这个问题在这里已经有了答案: R中“=”和“< - ”之间有什么区别? 6个答案 在某种意义上=和<-是等价的,但是后者是首选的,因为=也被覆盖以指定默认参数(其中<-不起作用)。 至于<<- ,它更棘手,不推荐。 在R中,沿任意代码执行的每一步都将与一堆环境相关联 - 当前环境,当前函数被调用的环境等等。运算符<<-试图将值分配给发现的最近对象在此环境层次结构中,如果没有找到,请在全局环境中进行分

Are `=` and `<

Possible Duplicate: Assignment operators in R: '=' and '<-' Is it just a style preference? As far as I can tell, they are the same. I see many people prefer the "longer" <- version and I can't tell why (perhaps keeping away from = and == confusions?) No, they are not exactly the same: the = operator cannot be used everywhere that <- can. The oper

是`=`和`<

可能重复: R中的赋值运算符:'='和'< - ' 这只是一种风格偏好? 据我所知,他们是一样的。 我看到很多人喜欢“长” <-也许保持远离版本,我不知道为什么=和== ?混乱) 不,它们不完全一样: =运算符不能用于<-可以的任何地方。 运算符< - 和=分配到它们被评估的环境中。 运算符< - 可以在任何地方使用,而运算符=只允许在最高级别(例如,在命令提示符处键入的完整表达式中)或作为

ing with the "$" function

I was going through some examples in hadley's guide to functionals, and came across an unexpected problem. Suppose I have a list of model objects, x=1:3;y=3:1; bah <- list(lm(x~y),lm(y~x)) and want to extract something from each (as suggested in hadley's question about a list called "trials"). I was expecting one of these to work: lapply(bah,`$`,i='call') # or... lapply

使用“$”功能

我正在通过hadley的函数指南中的一些例子,并遇到一个意想不到的问题。 假设我有一个模型对象的列表, x=1:3;y=3:1; bah <- list(lm(x~y),lm(y~x)) 并且想要从每个中提取一些东西(正如哈德利关于名为“试验”的列表所提出的问题)。 我期待其中的一个工作: lapply(bah,`$`,i='call') # or... lapply(bah,`$`,call) 但是,这些返回空值。 这似乎是我不滥用$函数,因为这些工作: `$`(bah[[1]],i='call') `$`(bah[[1]],

ddply for creating the union of lists

I have a data frame which contains a customerid, and a list. I would like to merge those list pertaining to the same customer. library(plyr) subsets <- list(c("a", "d", "e"), c("a", "b", "c", "e")) customerids <- c(1,1) transactions <- data.frame(customerid = customerids,subset =I(subsets)) > transactions customerid subset 1 1 a, d, e 2 1 a, b, c, e If I

ddply创建列表的联合

我有一个数据框,其中包含一个customerid和一个列表。 我想合并那些与同一客户有关的列表。 library(plyr) subsets <- list(c("a", "d", "e"), c("a", "b", "c", "e")) customerids <- c(1,1) transactions <- data.frame(customerid = customerids,subset =I(subsets)) > transactions customerid subset 1 1 a, d, e 2 1 a, b, c, e 如果我想用ddply合并子集,我会得到一个扩展结果

extract() data from raster with small polygons

Using R, I am trying to extract data from a raster layer using a polygon layer. The polygons are much smaller than the raster cells: Now I call extract() from raster library: a <- extract(raster, polygons, weights = TRUE, small = TRUE) a # ... # [[1551]] # value weight # 209 0.03 # top left cell - more than 50% of the polygon area There are two problems - the weight is the proportion

从具有小多边形的栅格提取()数据

使用R,我试图使用多边形图层从栅格图层中提取数据。 多边形比栅格单元小得多: 现在我从raster库中调用extract() : a <- extract(raster, polygons, weights = TRUE, small = TRUE) a # ... # [[1551]] # value weight # 209 0.03 # top left cell - more than 50% of the polygon area 有两个问题 - 权重是多边形覆盖的单元格面积的比例,权重四舍五入为1/100。 在我的情况下,输出中只有最左边的单元格(值209

Why "object 'x' not found" on a line that does not use x?

I get this: Error in paste0(width, on, k) : object 'x' not found I'm utterly confused why it complains about 'x' on this particular line! on is a character, width and k are numbers. x exists (it is a parameter of this function). That line and preceding ones look like: print(index(x)) stopifnot(length(index(x))>=1) #str(on);str(k);str(width) extra=list( paste0(width,on,k) )

为什么在不使用x的行上找不到“object”x'?

我得到这个: Error in paste0(width, on, k) : object 'x' not found 我完全困惑,为什么它在这个特定的行上抱怨'x'! on是一个字符, width和k是数字。 x存在(它是此函数的一个参数)。 该行和之前的行如下所示: print(index(x)) stopifnot(length(index(x))>=1) #str(on);str(k);str(width) extra=list( paste0(width,on,k) ) 但是,当我添加注释掉的线时,它甚至更加奇怪: Error in str(on) : object

Google Trends in R

I am trying to import Google Trend results into R. I have tried rGtrends and RGoogleTrends. The first seems to get stuck downloading the CSV file: > require(devtools) > install_github("rGtrends","emhart") > library(rGtrends) > my_terms <- c("Twitter", "Myspace") > twit_ms <- rGtrends(my_terms) Error in .jcall("RJavaTools", "Ljava/lang/Object;", "invokeMethod", cl, :

谷歌趋势在R

我正在尝试将Google趋势结果导入到R. 我尝试过rGtrends和RGoogleTrends。 第一个似乎卡住下载CSV文件: > require(devtools) > install_github("rGtrends","emhart") > library(rGtrends) > my_terms <- c("Twitter", "Myspace") > twit_ms <- rGtrends(my_terms) Error in .jcall("RJavaTools", "Ljava/lang/Object;", "invokeMethod", cl, : Traceback (most recent call last): File "<strin

Configuring NAMESPACE and DESCRIPTION when using a Suggested Package

I have written an R package which uses the rstudioapi::viewer() function. Obviously, not everyone uses RStudio. I am now running in circles trying to correctly configure the NAMESPACE and DESCRIPTION . So as not to force users to install a package which they don't need (and/or would be useless on their system), I tried putting rstudioapi in the Suggests section and call it conditional on

使用建议包时配置NAMESPACE和说明

我写了一个使用rstudioapi::viewer()函数的R包。 显然,并不是每个人都使用RStudio。 我现在正在试着正确配置NAMESPACE和DESCRIPTION 。 为了不强制用户安装他们不需要的软件包(和/或在他们的系统上无用),我尝试将rstudioapi放入Suggests部分,并将其rstudioapi可用条件: if(.Platform$GUI == "RStudio") { if ("rstudioapi" %in% rownames(installed.packages())) { rstudioapi::viewer(outfile_path) } else {