我有一个客户 ID 列表,每个 ID 都有他们使用的独特产品的列表。理论上最多可以有约 150 种独特的产品。
df <- tibble(ID = c(1,1,1,2,2,3,3,4),
prod = c("Prod1", "Prod2", "Prod3", "Prod1", "Prod4", "Prod3", "Prod5", "Prod2"))
Run Code Online (Sandbox Code Playgroud)
由此,我需要获取每个 ID 的所有可能的产品组合,而不仅仅是最高级别(按 ID 分组)。也就是说,包括所有产品的组合(如 Expand_grid() 所做的那样),但也包括1,...,n 个元素的所有组合,其中n是 ID 具有的唯一产品的数量。
因此,最终数据集应如下所示:
df_results <- tibble(ID = c(1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 3, 3, 3, 4),
combo = c("Prod1", "Prod2", "Prod3", "Prod1|Prod2", "Prod1|Prod3", "Prod2|Prod3", "Prod1|Prod2|Prod3",
"Prod1", "Prod4", "Prod1|Prod4",
"Prod3", "Prod5", "Prod3|Prod5",
"Prod2"))
Run Code Online (Sandbox Code Playgroud) 我有两列布局,右侧有灰色侧边栏.当左列的高度增加时(由于内容被动态扩展),我需要侧边栏的高度扩展.我可以让侧边栏适合静态页面,但我无法通过页面的其余部分来增加它的大小.做了一些谷歌搜索,但找不到适合我的解决方案.
有谁知道如何做到这一点?
我一直在尝试使用核心JSF实现表行扩展/折叠的功能,并且我还必须保留排序.在核心JSF中有没有办法实现这个功能?
我正在为课堂写作模拟,其中一部分涉及生物的繁殖.我的生物被保存在一个阵列中,我需要在它们繁殖时增加阵列的大小.因为我有多个生物的多个类,我使用了一个模板:
template <class orgType>
void expandarray(orgType* oldarray, int& numitems, int reproductioncount)
{
orgType *newarray = new orgType[numitems+reproductioncount];
for (int i=0; i<numitems; i++) {
newarray[i] = oldarray[i];
}
numitems += reproductioncount;
delete[] oldarray;
oldarray = newarray;
newarray = NULL;
}
Run Code Online (Sandbox Code Playgroud)
但是,这个模板似乎在某种程度上破坏了我的数据.我可以在没有再现的情况下运行该程序(注释掉对expandarray的调用),但调用此函数会导致程序崩溃.程序在expandarray函数中不会崩溃,但稍后会在访问冲突时崩溃.
我已经编写了数百次扩展数组的函数,而且我不知道这次搞砸了什么.我的功能有什么明显的错误吗?它看起来对你好吗?
编辑:谢谢大家的帮助.我无法相信我错过了一些如此明显的东西.为了回应使用std::vector:我们还没有在课堂上讨论它,而且看起来很傻,我需要使用我们教过的方法编写代码.
我有一个表,并希望使一些行可扩展 - 单击一行将展开该父行下的其他几行.并非所有行都应该是可扩展的.jQuery会好的.任何人都可以告诉我如何实现这一目标或指向手册吗?
谢谢.
有没有办法扩展动态内存阵列?像这样:
int *a = new int[5];
*a = new int[2];
Run Code Online (Sandbox Code Playgroud)
这合法吗?
我的init文件中有这个简洁的函数:
(defun comment-or-uncomment-region-or-line()
"Comments or uncomments the region or the current line if there's no active region."
(interactive)
(let (beg end)
(if (region-active-p)
(setq beg (region-beginning) end (region-end))
(setq beg (line-beginning-position) end (line-end-position))
)
(comment-or-uncomment-region beg end)
(next-line)
)
)
Run Code Online (Sandbox Code Playgroud)
但是,我不喜欢它的是以下情况:
Lorem ipsum dolor sit amet, consec|tetur adipisicing elit, sed do eiusmod tempor
incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud
exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure …Run Code Online (Sandbox Code Playgroud) <style>
.classname {
min-width:248px;
height:40px;
max-width:498px;
border:1px solid red;
float:left;
}
</style>
<div id="maindiv" style="width:3134px;border:1px solid green;height:90px;">
<div class="classname">
</div>
<div class="classname">
</div>
<div class="classname">
</div>
</div>
Run Code Online (Sandbox Code Playgroud)
所以无论我有多少个孩子,maindiv我都希望他们扩展到父宽度大小的全尺寸.例如:如果maindiv的宽度为1200px,则每个400px的孩子如果是3或300px,如果是4只CSS解决方案
我有一个数据帧
df <- data.frame(
id = c(1, 1, 1, 2, 2, 3, 3, 3, 3, 4),
date = c("1985-06-19", "1985-06-19", "1985-06-19", "1985-08-01",
"1985-08-01", "1990-06-19", "1990-06-19", "1990-06-19",
"1990-06-19", "2000-05-12"),
spp = c("a", "b", "c", "c", "d", "b", "c", "d", "a", "b"),
y = rpois(10, 5))
id date spp y
1 1 1985-06-19 a 6
2 1 1985-06-19 b 3
3 1 1985-06-19 c 7
4 2 1985-08-01 c 7
5 2 1985-08-01 d 6
6 3 1990-06-19 b 5
7 3 …Run Code Online (Sandbox Code Playgroud) 我有两个div彼此相邻,并希望使用切换功能水平折叠一个div(侧边栏),同时展开另一个(Map)以获取前者的全宽.然后我需要切换以将两个div恢复到原始宽度/位置.我可以让它做第一次操作,但我不知道如何做反向.见小提琴:
$(document).ready(function(){
$("#toggle").click(function(){
$("#sidebar").animate({width: 'toggle'});
$("#map").animate({width: '100%'});
});
});
Run Code Online (Sandbox Code Playgroud)