Beispiel #1
0
 public Frame subframe(String[] names) {
   Vec[] vecs = new Vec[names.length];
   HashMap<String, Integer> map = new HashMap<String, Integer>();
   for (int i = 0; i < _names.length; ++i) map.put(_names[i], i);
   for (int i = 0; i < names.length; ++i)
     if (map.containsKey(names[i])) vecs[i] = _vecs[map.get(names[i])];
     else throw new IllegalArgumentException("Missing column called " + names[i]);
   return new Frame(names, vecs);
 }
Beispiel #2
0
 private static int guessNcols(ParserSetup setup, String[][] data) {
   int res = data[0].length;
   if (setup._header) return res;
   boolean samelen = true;
   for (String[] s : data) samelen &= (s.length == res);
   if (samelen) return res;
   // we don't have lines of same length, pick the most common length
   HashMap<Integer, Integer> lengths = new HashMap<Integer, Integer>();
   for (String[] s : data) {
     if (!lengths.containsKey(s.length)) lengths.put(s.length, 1);
     else lengths.put(s.length, lengths.get(s.length) + 1);
   }
   int maxCnt = 0;
   for (Map.Entry<Integer, Integer> e : lengths.entrySet())
     if (e.getValue() > maxCnt) {
       maxCnt = e.getValue();
       res = e.getKey();
     }
   return res;
 }