唯一的变量组合之间的观察数量的子集数据

时间:2017-05-03 16:19:00

标签: r

我有一个数据框:

descriptionin = c("sample1","sample1","sample1","sample1","sample1","sample1","sample1","sample1","sample2","sample2","sample3","sample3","sample3","sample3","sample3","sample3")
dilutionin = c(1,10,100,1000,1,10,100,1000,5,5,2,8,32,2,8,32)
conditionin = c("cond1","cond1","cond1","cond1","cond2","cond2","cond2","cond2","cond1","cond2","cond1","cond1","cond1","cond2","cond2","cond2")

testin <- data.frame(descriptionin,dilutionin,conditionin)

并希望将数据框子集到此:

descriptionout = c("sample1","sample1","sample1","sample1","sample1","sample1","sample1","sample1","sample3","sample3","sample3","sample3","sample3","sample3")
dilutionout = c(1,10,100,1000,1,10,100,1000,2,8,32,2,8,32)
conditionout = c("cond1","cond1","cond1","cond1","cond2","cond2","cond2","cond2","cond1","cond1","cond1","cond2","cond2","cond2")

testout <- data.frame(descriptionout,dilutionout,conditionout)

为了解释,我想通过每个唯一的描述/条件组合对数据帧进行子集化,该组合具有多个稀释数(在这种情况下为1,但实际数据集将为3)稀释。

由于

1 个答案:

答案 0 :(得分:2)

一个选项是Multimap<MyClass, MyOtherClass> myMultiMap = HashMultimap.create(); // ... build your multimap Map<MyClass, Set<MyOtherClass>> map = Maps.newHashMap(); for (Map.Entry<MyClass, Collection<MyOtherClass>> entry : myMultiMap.asMap().entrySet()) { map.put(entry.getKey(), ImmutableSet.copyOf(entry.getValue())); } 。将'data.frame'转换为'data.table'(data.table),按'descriptionin'和'conditionin'分组,我们找到组中元素的行索引(setDT(testin))多个.I'稀释'并使用该索引对行进行子集

unique