3 回答
TA贡献1836条经验 获得超3个赞
我有一个带有p值列的dataframe,我想对这些p值进行选择。
> pvalues_anova
[1] 9.693919e-01 9.781728e-01 9.918415e-01 9.716883e-01 1.667183e-02
[6] 9.952762e-02 5.386854e-01 9.997699e-01 8.714044e-01 7.211856e-01
[11] 9.536330e-01 9.239667e-01 9.645590e-01 9.478572e-01 6.243775e-01
[16] 5.608563e-01 1.371190e-04 9.601970e-01 9.988648e-01 9.698365e-01
[21] 2.795891e-06 1.290176e-01 7.125751e-01 5.193604e-01 4.835312e-04
选择方式:
anovatest<- results[ - which(results$pvalues_anova < 0.8) ,]
如果我在R中使用它,这个函数可以很好地工作,但是如果我在另一个应用程序(银河)中运行它,没有e-01G.4.835312e-04不会被扔出去。
还有其他方法来标注p值吗,比如0.0004835312而不是4.835312e-04?你可以:
使用以列表作为值的映射。Map<KeyType, List<ValueType>>.
创建一个新的包装类,并将此包装器的实例放在映射中。Map<KeyType, WrapperType>.
使用元组类(节省创建大量包装器)。Map<KeyType, Tuple<Value1Type, Value2Type>>.
并排使用多重地图。
实例
1.以列表为值的映射
// create our map
Map<String, List<Person>> peopleByForename = new HashMap<>();
// populate it
List<Person> people = new ArrayList<>();
people.add(new Person("Bob Smith"));
people.add(new Person("Bob Jones"));
peopleByForename.put("Bob", people);
// read from it
List<Person> bobs = peopleByForename["Bob"];
Person bob1 = bobs[0];
Person bob2 = bobs[1];
这种方法的缺点是列表没有绑定到两个值。
2.使用包装类
// define our wrapper
class Wrapper {
public Wrapper(Person person1, Person person2) {
this.person1 = person1;
this.person2 = person2;
}
public Person getPerson1 { return this.person1; }
public Person getPerson2 { return this.person2; }
private Person person1;
private Person person2;
}
// create our map
Map<String, Wrapper> peopleByForename = new HashMap<>();
// populate it
Wrapper people = new Wrapper();
peopleByForename.put("Bob", new Wrapper(new Person("Bob Smith"),
new Person("Bob Jones"));
// read from it
Wrapper bobs = peopleByForename.get("Bob");
Person bob1 = bobs.getPerson1;
Person bob2 = bobs.getPerson2;
这种方法的缺点是,您必须为所有这些非常简单的容器类编写大量的锅炉板代码。
3.使用元组
// you'll have to write or download a Tuple class in Java, (.NET ships with one)
// create our map
Map<String, Tuple2<Person, Person> peopleByForename = new HashMap<>();
// populate it
peopleByForename.put("Bob", new Tuple2(new Person("Bob Smith",
new Person("Bob Jones"));
// read from it
Tuple<Person, Person> bobs = peopleByForename["Bob"];
Person bob1 = bobs.Item1;
Person bob2 = bobs.Item2;
在我看来,这是最好的解决办法。
4.多重地图
// create our maps
Map<String, Person> firstPersonByForename = new HashMap<>();
Map<String, Person> secondPersonByForename = new HashMap<>();
// populate them
firstPersonByForename.put("Bob", new Person("Bob Smith"));
secondPersonByForename.put("Bob", new Person("Bob Jones"));
// read from them
Person bob1 = firstPersonByForename["Bob"];
Person bob2 = secondPersonByForename["Bob"];
此解决方案的缺点是,这两个映射之间的关系并不明显,编程错误可能导致两个映射不同步。
TA贡献1817条经验 获得超6个赞
HashMap<K, ArrayList<String>> map = new HashMap<K, ArrayList<String>>()
MultiValuedMap<K, String> map = new MultiValuedHashMap<K, String>();
map.put(key, "A");map.put(key, "B");map.put(key, "C");Collection<String> coll = map.get(key);
coll
添加回答
举报