Why is `[` better than `subset`?

When I need to filter a data.frame, ie, extract rows that meet certain conditions, I prefer to use the subset function: subset(airquality, Month == 8 & Temp > 90) Rather than the [ function: airquality[airquality$Month == 8 & airquality$Temp > 90, ] There are two main reasons for my preference: I find the code reads better, from left to right. Even people who know nothing abo

为什么``比'subset`好?

当我需要过滤数据帧时,即提取符合某些条件的行时,我更愿意使用subset函数: subset(airquality, Month == 8 & Temp > 90) [函数: airquality[airquality$Month == 8 & airquality$Temp > 90, ] 我的偏好主要有两个原因: 我发现代码读起来更好,从左到右。 即使对R一无所知的人也可以知道上面的subset声明正在做什么。 因为列可以在select表达式中被称为变量,所以我可以节省一些击键。 在我上面的例

What is the difference between require() and library()?

require()和library()之间有什么区别? There's not much of one in everyday work. However, according to the documentation for both functions (accessed by putting a ? before the function name and hitting enter), require is used inside functions, as it outputs a warning and continues if the package is not found, whereas library will throw an error. Another benefit of require() is that it retu

require()和library()之间有什么区别?

require()和library()之间有什么区别? 日常工作中没有太多。 但是,根据这两个函数的文档(通过在函数名称前面加一个?并敲入回车来访问), require在函数内部使用,因为它会输出警告,如果找不到包,则继续;而library会抛出错误。 require()另一个好处是它默认返回一个逻辑值。 如果包已加载则为TRUE否则为FALSE 。 > test <- library("abc") Error in library("abc") : there is no package called 'abc' > te

What's the difference between `=` and `<

Possible Duplicate: Assignment operators in R: '=' and '<-' I'm using R 2.8.1 and it is possible to use both = and <- as variable assignment operators. What's the difference between them? Which one should I use? From here: The operators <- and = assign into the environment in which they are evaluated. The operator <- can be used anywhere, whereas the

`=`和`<有什么区别?

可能重复: R中的赋值运算符:'='和'< - ' 我正在使用R 2.8.1,可以同时使用=和<-作为变量赋值操作符。 他们之间有什么区别? 我应该使用哪一个? 从这里: 运算符< - 和=分配到它们被评估的环境中。 运算符< - 可以在任何地方使用,而运算符=只允许在最高级别(例如,在命令提示符处键入的完整表达式中)或作为表达式支撑列表中的子表达式之一。 从Robert和Casella的“用R介绍蒙特卡洛

If/else suggests package description

Is there a way to do an ifelse statement in the suggests field of a package dependent upon OS type. For instance the installr package would be nice for a windows user and heavily related to a package but it's only available for Windows users. This means that a note will be raised in the CRAN check for a Mac or Linux user. Currently I have a package that looks something like this: Package

如果/ else建议包描述

有没有办法在依赖于OS类型的包的建议字段中执行ifelse语句? 例如, installr软件包对于Windows用户来说很不错,而且与软件包密切相关,但它只适用于Windows用户。 这意味着在Mac或Linux用户的CRAN检查中会发出一条提示。 目前我有一个看起来像这样的包: Package: awesomeR Type: Package Title: A collection of awesomeness Version: 0.1.2 Date: 2013-02-18 Author: Guy Smiley Maintainer: Guy <guy@gmail.com> D

Drop data frame columns by name

I have a number of columns that I would like to remove from a data frame. I know that we can delete them individually using something like: df$x <- NULL But I was hoping to do this with fewer commands. Also, I know that I could drop columns using integer indexing like this: df <- df[ -c(1, 3:6, 12) ] But I am concerned that the relative position of my variables may change. Given ho

按名称删除数据框列

我有一些我想从数据框中删除的列。 我知道我们可以使用类似的方法单独删除它们: df$x <- NULL 但我希望用更少的命令来做到这一点。 另外,我知道我可以像这样使用整数索引来删除列: df <- df[ -c(1, 3:6, 12) ] 但我担心我的变量的相对位置可能会改变。 鉴于R是多么强大,我认为可能有比逐个删除每列更好的方法。 你可以使用一个简单的名字列表: DF <- data.frame( x=1:10, y=10:1, z=rep(5,10),

Convert data.frame columns from factors to characters

I have a data frame. Let's call him bob : > head(bob) phenotype exclusion GSM399350 3- 4- 8- 25- 44+ 11b- 11c- 19- NK1.1- Gr1- TER119- GSM399351 3- 4- 8- 25- 44+ 11b- 11c- 19- NK1.1- Gr1- TER119- GSM399352 3- 4- 8- 25- 44+ 11b- 11c- 19- NK1.1- Gr1- TER119- GSM399353 3- 4- 8- 25+ 44+ 11b- 11c- 19- NK1.1- Gr1- TER119- GSM399354 3- 4- 8- 25+ 44+ 11b-

将data.frame列从因素转换为字符

我有一个数据框。 让我们叫他bob : > head(bob) phenotype exclusion GSM399350 3- 4- 8- 25- 44+ 11b- 11c- 19- NK1.1- Gr1- TER119- GSM399351 3- 4- 8- 25- 44+ 11b- 11c- 19- NK1.1- Gr1- TER119- GSM399352 3- 4- 8- 25- 44+ 11b- 11c- 19- NK1.1- Gr1- TER119- GSM399353 3- 4- 8- 25+ 44+ 11b- 11c- 19- NK1.1- Gr1- TER119- GSM399354 3- 4- 8- 25+ 44+ 11b- 11c- 19- NK

Arrange many plots using gridExtra

I have spent many hours trying to fit 11 graphs in one plot and arrange them using gridExtra but I have failed miserably, so I turn to you hoping you can help. I have 11 classifications of diamonds (call it size1 ) and other 11 classifications ( size2 ) and I want to plot how the median price for each increasing size1 and increasing clarity (from 1 to 6) varies by increasing size2 of the diamon

使用gridExtra排列许多图

我花了很多时间试图在一个阴谋中安装11张图表,并使用gridExtra安排,但是我失败了,所以我希望你能帮上忙。 我有11个钻石分类(称为size1 )和其他11个分类( size2 ),我想绘制每个不断增加的size1的中间价格和增加的clarity (从1到6)的变化情况,钻石的size1增加size2 ,所有11个图表在同一个图表中。 我尝试使用gridExtra在其他帖子中建议,但传说是远离右边,所有图形都挤在左边,你能帮我弄清楚gridExtra中传说的“宽

multicore and data.table in R

I am attempting to use multicore function parallel with data.table and am unable to quite come up with the right way to do this. Code: require(multicore) require(data.table) dtb = data.table(a=1:10, b=1:2) x = dtb[,parallel(a+1),by=b] > x b pid fd 1: 1 12243 3 2: 1 12243 6 3: 2 12247 4 4: 2 12247 8 I would like to call collect() on this but these are no longer parallel objects. H

R中的多核和data.table

我正在尝试使用与data.table parallel multicore功能,并且无法完全按照正确的方式来执行此操作。 码: require(multicore) require(data.table) dtb = data.table(a=1:10, b=1:2) x = dtb[,parallel(a+1),by=b] > x b pid fd 1: 1 12243 3 2: 1 12243 6 3: 2 12247 4 4: 2 12247 8 我想对此调用collect() ,但这些不再是parallel对象。 应该怎么做? 我认为这符合你想要的内容: collect(dtb[, list(jobs =

called when you say it out loud?

How do you pronounce this "left arrow" combination of less than and dash? You can use it for assignment in R instead of =, and I want to know how to say (for example) "Use <- instead of equals". I would just say 'equals', or 'is assigned' if you feel like talking more. But seriously, I do not know of any convention for this assignment operator.

当你大声说出来时称呼?

你如何发音这个“左箭头”小于和破折号的组合? 你可以在R中使用它来代替=,并且我想知道怎么说(例如)“使用< - 而不是等于”。 如果您想谈更多的话,我只会说'平等',或'已分配'。 但严重的是,我不知道这个任务运营商有任何约定。

Queries in MongoDB

I'm trying to use rmongodb to fetch information from a MongoDB database for further processing in R. However, I have some difficulties to really get started. This one works: cursor <- mongo.find(mongo, "people", query=list(last.name="Smith", first.name="John"), fields=list(address=1L, age=1L)) while (mongo.cursor.next(cursor)){ print(mongo.cursor.value(cursor))} Now,

MongoDB中的查询

我试图使用rmongodb从MongoDB数据库中获取信息以便在R中进一步处理。但是,我真的很难开始真正开始。 这一个作品: cursor <- mongo.find(mongo, "people", query=list(last.name="Smith", first.name="John"), fields=list(address=1L, age=1L)) while (mongo.cursor.next(cursor)){ print(mongo.cursor.value(cursor))} 现在,如果我想要找到名字是“John”或“Bob”或“Catherine”的人,该怎么办? 我试