首页
\
问答
\
不同的默认'initialCapacity'HashSet和LinkedHashSet(Different default 'initialCapacity' HashSet and LinkedHashSet)
不同的默认'initialCapacity'HashSet和LinkedHashSet(Different default 'initialCapacity' HashSet and LinkedHashSet)
从集合构造
HashSet
和LinkedHashSet
,initialCapacity
在默认实现中设置为不同的值。HashSet的:
public HashSet(Collection<? extends E> c) { map = new HashMap<>(Math.max((int) (c.size()/.75f) + 1, 16)); addAll(c); }
LinkedHashSet:
public LinkedHashSet(Collection<? extends E> c) { super(Math.max(2*c.size(), 11), .75f, true); addAll(c); }
我确信有一个完全有效的理由,但我看不到它。
When constructing a
HashSet
and aLinkedHashSet
from a collection, theinitialCapacity
is set to different values in the default implementation.HashSet:
public HashSet(Collection<? extends E> c) { map = new HashMap<>(Math.max((int) (c.size()/.75f) + 1, 16)); addAll(c); }
LinkedHashSet:
public LinkedHashSet(Collection<? extends E> c) { super(Math.max(2*c.size(), 11), .75f, true); addAll(c); }
I'm sure there is a perfectly valid reason for this, but I fail to see it.
原文:https://stackoverflow.com/questions/41692230
更新时间:2023-05-14 19:05
最满意答案
我认为你正在寻找:
library(plyr) ddply(diam,"color", function(x) { w <- wilcox.test(price~cut,data=x) with(w,data.frame(statistic,p.value)) })
(用
t.test
代替wilcox.test
似乎也可以正常工作。)结果:
color statistic p.value 1 D 339753.5 4.232833e-24 2 E 591104.5 6.789386e-19 3 F 731767.5 2.955504e-11 4 G 950008.0 1.176953e-12 5 H 611157.5 2.055857e-17 6 I 213019.0 3.299365e-04 7 J 56870.0 2.364026e-01
I think you're looking for:
library(plyr) ddply(diam,"color", function(x) { w <- wilcox.test(price~cut,data=x) with(w,data.frame(statistic,p.value)) })
(Substituting
t.test
forwilcox.test
seems to work fine too.)results:
color statistic p.value 1 D 339753.5 4.232833e-24 2 E 591104.5 6.789386e-19 3 F 731767.5 2.955504e-11 4 G 950008.0 1.176953e-12 5 H 611157.5 2.055857e-17 6 I 213019.0 3.299365e-04 7 J 56870.0 2.364026e-01
相关问答
更多-
我认为你正在寻找: library(plyr) ddply(diam,"color", function(x) { w <- wilcox.test(price~cut,data=x) with(w,data.frame(statistic,p.value)) }) (用t.test代替wilcox.test似乎也可以正常工作。) 结果: color statistic p.value 1 D 339753.5 4.2 ...
-
ggplot2:::Stat可以用来访问非导出的对象。 ggplot2:::Stat can be used to access the non-exported object.
-
您需要在两个比例(fill和x)上设置drop = FALSE,如下所示: library(ggplot2) df <- data.frame(type=c("A", "A", "A", "B", "B"), group=rep("group1", 5)) df1 <- data.frame(type=c("A", "A", "A", "B", "B", "A", "A", "C", "B", "B"), group=c(rep("group1", 5),rep("group2", 5))) df$type ...
-
我认为这个数字显示了你想要的东西。 我还在代码中添加了一些部分,因为你是ggplot2 。 拿走或离开它们,但我做的事情是出版质量数字: wtOut = wilcox.test(df1$var1[df1$outcome<=1], df1$var1[df1$outcome>1]) exampleOut <- ggplot(df1, aes(x = as.factor(outcome), y = as.numeric(var1), fill=outcome)) + geom_boxplo ...
-
使用ggplot2的交互图(interaction plot using ggplot2)[2023-11-26]
tmp <- as.data.frame(effect("hp:wt", model, list(wt=c(2.2,3.2,4.2)))) ggplot(data=tmp, aes(x=hp, y=fit, colour=as.factor(wt))) + geom_line() + labs(colour="wt") tmp <- as.data.frame(effect("hp:wt", model, list(wt=c(2.2,3.2,4.2)))) ggplot(dat ... -
与@Richard类似的想法,但使用zoo包。 library(zoo) x = data.frame(x = 1:6, y = c(0,0,10,10,0,0)) ggplot(x, aes(x, y, col=rollmean(y, 2, fill = 0))) + geom_line(size=5) Similar idea as @Richard, but use the zoo package. library(zoo) x = data.frame(x = 1:6, y = c(0,0,10, ...
-
ggplot2 position ='dodge'生成太宽的条形图(ggplot2 position='dodge' producing bars that are too wide)[2024-01-14]
ggplot的默认选项产生了我认为你描述的内容。 scales="free"和space="free"选项与你想要的相反,所以只需从代码中删除它们。 此外, geom_bar的默认stat geom_bar是通过计数进行聚合,因此您不必明确指定您的统计信息。 ggplot(df, aes(x=a, fill=a)) + geom_bar() + facet_grid(~b) The default options in ggplot produces what I think you describe. ... -
两种方法: 示例数据: dat <- data.frame(value=runif(26)*10, grouping=c(rep("Group 1",10), rep("Group 2",10), rep("Group 3",6)), letters=LETTERS[1:26]) head(dat) value ...
-
警告包括In loop_apply(n, do.ply) ,它表示包plyr可能涉及正在发生的任何事情。 当我加载包plyr_1.8.2时,我可以重现错误。 更新到当前开发版本plyr_1.8.2.9000可以解决此问题。 The warning includes In loop_apply(n, do.ply), which indicates that package plyr might be involved in whatever is going on. When I loaded packag ...
-
因此,看到这是一个下雨的下午,我做到了这一点: set.seed(1234) n <- 50 shapes <- data.frame(Exposure=sample(c("CON CCCP","CON DMSO","HF CCCP","HF DMSO"),n, replace=T),Area=runif(n,0,10)) data.summary.area <- data.frame(treatment.area = leve ...