- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
这是对 Reordering factor gives different results, depending on which packages are loaded 的跟进,还有另一个相关问题。
@Andrie的答案是正确的,并遵循 @David Lovell的评论,我因此而成为第三个困惑的灵魂。
在我的例子中,这是因为我加载了 ROCR
,它依赖于 gplots
,它依赖于 gdata
,而我没有甚至听说过gdata
,说明我无知,因此没有想到去搜索它。
我发现了另一个怪癖,这让我的案例更难解决,这就是这个问题的重点。 gdata:::reorder.factor
以不同方式处理整数和数字。举例说明:
library(gdata)
x <- factor(letters[1:6])
y <- c(1,4,3,5,6,2)
z <- c(1.1,2.4,1.3,2.5,2.6,1.2)
stats:::reorder.default(x, y, function(X)-X) #edbcfa - correct
stats:::reorder.default(x, z, function(X)-X) #edbcfa
stats:::reorder.default(x, -y) #edbcfa
stats:::reorder.default(x, -z) #edbcfa
gdata:::reorder.factor(x, y, function(X)-X) #edbcfa
gdata:::reorder.factor(x, z, function(X)-X) #bdeafc - weird
gdata:::reorder.factor(x, -y) #abcdef - no reordering
gdata:::reorder.factor(x, -z) #abcdef - no reordering
主要是我感兴趣的 bdeafc。它的小数点前的位是正确的,因为 2.x 在 1.x 之前,但小数点后的部分点按正常顺序排列,而不是倒序排列:x.1 在 x.2 在 x.3 之前。
这是为什么?
最佳答案
嗯,这似乎是因为 gdata:::reorder.factor
接受了一个名为 sort
的参数,默认情况下它的值为 mixedsort
.此 mixedsort
参数使用包 gtools
中的 mixedorder
函数。通过加载 gtools
并执行 ?mixedorder
,您可以找出发生这种情况的原因:
?mixedorder
Order or Sort strings with embedded numbers so that the numbers are in the correct order:
These functions sort or order character strings containing numbers so that the numbers are numerically sorted rather than sorted by character value. I.e. "Asprin 50mg" will come before "Asprin 100mg". In addition, case of character strings is ignored so that "a", will come before "B" and "C".
还有 ?reorder.factor
清楚地说明了这一点:
?gdata:::reorder.factor
If sort is provided (as it is by default): The new factor level names are generated by applying the supplied function to the existing factor level names. With sort=mixedsort the factor levels are sorted so that combined numeric and character strings are sorted in according to character rules on the character sections (including ignoring case), and the numeric rules for the numeric sections. See mixedsort for details.
您必须为 sort
参数提供 NULL 值,以便默认情况下不采用 mixedsort
。
gdata:::reorder.factor(x, z, function(X)-X, sort=NULL)
# [1] a b c d e f
# Levels: e d b c f a
或者,正如@BenBolker 在评论中指出的那样,您可以简单地提供“排序”参数 sort
:
gdata:::reorder.factor(x, z, function(X)-X, sort=sort)
对于 future ,debugonce
是您处理这些事情的 friend 。通过做
debugonce(gdata:::reorder.factor)
gdata:::reorder.factor(x, z, function(X)-X)
(然后按回车并检查输出)您会发现问题出在正在运行的最后几行:
else if (!missing(FUN))
new.order <- names(sort(tapply(X, x, FUN, ...)))
对于您的数据,
> X
# [1] 1.1 2.4 1.3 2.5 2.6 1.2
> x
# [1] a b c d e f
# Levels: a b c d e f
并且,tapply(...)
给出:
> tapply(X, x, FUN, ...)
# a b c d e f
# -1.1 -2.4 -1.3 -2.5 -2.6 -1.2
在这里,“排序”应该给出:
> base:::sort(tapply(X, x, FUN, ...))
# e d b c f a
# -2.6 -2.5 -2.4 -1.3 -1.2 -1.1
但是它给出了:
# b d e a f c
# -2.4 -2.5 -2.6 -1.1 -1.2 -1.3
这是因为正在调用的“sort”不是来自 base,这可以通过在调试器中键入“sort”来查看:
> sort # from within the function call (using debugonce)
# function (x)
# x[mixedorder(x)]
# <environment: namespace:gtools>
mixedorder
是包 gtools
中的一个函数。由于该命令获取 names
并且排序错误,因此获取的顺序错误。所以基本上问题是被调用的 sort
是 mixedsort
而不是 base:::sort
。
通过安装 gtools
并执行以下操作很容易验证这一点:
require(gtools)
gtools:::mixedorder(c(-2.4, -2.5, -2.6))
# [1] 1 2 3
order(c(-2.4, -2.5, -2.6))
# [1] 3 2 1
因此,您必须提供 sort=NULL
以确保不会发生这种情况。
关于r - 为什么 gdata:::reorder.factor 与 stats:::reorder.default 对于整数和 double 的行为不同?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20317343/
在 Gdata 中使用电子表格 api 获取电子表格列表, Oauth1 方式 spreadSheetService = gdata.spreadsheet.service.SpreadsheetsS
当我读这两本书时,它们似乎针对同一件事并且由同一作者撰写。那么这两者有什么不同呢? 谢谢 最佳答案 service.py 模块用于该库的 v1 实现,通过引入 client.py 实现了该库的显着改进
Zend GData 文档中的 $worksheetId 应该是什么? http://framework.zend.com/manual/en/zend.gdata.spreadsheets.html
我已经有了 access_token 和 refresh_token,但我想不出一种方法来创建授权的 gdata 客户端,而无需在 gdata 中完成整个 token 生成工作流程。 最佳答案 所以我
我需要更新 iPhone 应用程序上的 Google 文档电子表格中的一些单元格。 我已经下载了 GData 源代码和示例项目(不是 iphone 专用的),但我似乎无法让它工作。有人知道有什么好的(
有相似之处(在身份验证和其他一些操作中,例如都可以获取文档列表),但有什么区别?为什么我们需要两者? 我正在学习 gdata api,我意识到我可以通过这种方式使用 OAuth 访问 token 登录
我会在表格中滑动所有单元格,但我没有解决。我的代码是: SpreadsheetService service = new SpreadsheetService("MyApp"); try{
我正在使用 Google gdata 库。我将其安装在我的本地 Maven 存储库中,因为无法使用 pom 从 Maven Central 获取它。 我想将其移至我的 WEB-INF/lib 目录,这
我已经使用 MAC 的 GData 电子表格代码编写了相应的 iPhone 版本(相同的代码),但抛出了异常:[GDataEntryBase worksheetsFeedURL]:无法识别的选择器发送
我正在使用以下代码将 .mov 文件上传到 youtube。上传成功,但视频没有任何音频。如果我做错了什么,请告诉我...... - (void)uploadVideoFile { NSStrin
如何获取youtube feed标签并将其转换为android中的字符串/整数。 我想使用标签,以及属性:totalUploadViewCount? https://developers.google
我只是在使用此网址在YouTube上用“害怕”一词找到收视率最高的视频。 http://gdata.youtube.com/feeds/api/standardfeeds/top_rated?q=sc
我正在使用GData Api从ios应用程序在youtube上上传视频。 它成功上传了视频,但是音频丢失了。 我正在使用.mp4格式的视频。 有人有线索吗? 谢谢 -(BOOL) setupWrite
我正在尝试将 GData 框架包含在我的项目中几个小时,但我完全迷失了。我正在尝试按照 gdata-objectivec-client 页面 ( https://code.google.com/p/g
有什么方法可以避免使用gdata api时ClientLogin有时需要的验证码吗? 最佳答案 您可以尝试一下。希望这是一回事。 http://www.gmailhelp.com/recent-art
阅读 documentation 后和 Google's developer guide ,我没有找到添加第二个地址线的方法。 例如,如果我想将此地址存储为 Google 联系人: 先生。王牌人物 露
正在使用 gdata 在 appengine 上使用 python 来更新我的驱动器上的电子表格文件。一切都工作正常,直到最近,代码开始遇到错误。 import webapp2 import
我想使用它的 API 从 google 服务器获取 xml 数据。所以,我无法对回复进行任何更改。那么,我如何让这个电话对我有用: $.ajax({ type: 'POST',
我以前问过这个问题,但没有答案。于是又问。 我只是不知道要使用哪个 gdata 框架类,以便我可以搜索 youtube 视频。我通过调试代码使用了一些类,但我认为框架太深了,可能需要很多时间才能解决这
Youtube API文档指出,可以按照以下链接在视频获取过程中搜索多个关键字。 https://developers.google.com/youtube/2.0/reference#Searchi
我是一名优秀的程序员,十分优秀!