logo
down
shadow

How to sort factors


How to sort factors

By : user2951496
Date : November 18 2020, 11:13 AM
like below fixes the issue First of all your code has a lot of compilation errors.
No need to sort the array. Only store the positive factors in the array.
code :


Share : facebook icon twitter icon
R: Sort Frame by two Columns with factors

R: Sort Frame by two Columns with factors


By : Andres Martinez
Date : March 29 2020, 07:55 AM
I wish did fix the issue. You can convert the Size column into an ordered factor list:
code :
> d <- read.table(header=T, text='    Values  Size       Length
+     1       "Small"      10
+     2       "Big"        6
+     3       "Small"      30
+     4       "Medium"     22
+     5       "Very Small" 17
+     6       "Small"      16')

> d$Size <- factor(d$Size, levels=c("Very Small", "Small", "Medium", "Big"))
> d[order(d$Size), ]
  Values       Size Length
5      5 Very Small     17
1      1      Small     10
3      3      Small     30
6      6      Small     16
4      4     Medium     22
2      2        Big      6
Sort sql rows by multiple factors but in proportion in php?

Sort sql rows by multiple factors but in proportion in php?


By : user2918420
Date : March 29 2020, 07:55 AM
like below fixes the issue An ORDER BY can have multiple columns - so, ORDER BY Price, Quality, Weight, Height would first sort by Price, then Quality, etc.... Is this what you want or are you asking something else?
Sort dictionary based on 2 factors

Sort dictionary based on 2 factors


By : Sergey Yepaneshnikov
Date : March 29 2020, 07:55 AM
it fixes the issue Have you tried adding another order condition after the first one like below ?
code :
var dictionarySortedByCount = dictionary
        .OrderByDescending(x => x.Value.Count)
        .ThenBy(x => x.Value[0].ObjectId)
        .ToDictionary(x => x.Key, x => x.Value);
How to sort Map by two factors?

How to sort Map by two factors?


By : Nima M
Date : March 29 2020, 07:55 AM
it fixes the issue Your if condition should check if the previous comparison returned 0 then perform the following comparison like this:
code :
if (c == 0) 
   return Integer.compare(o1.getKey().length(), o2.getKey().length());
list.sort(Map.Entry.<String, Integer>comparingByValue()
                      .thenComparingInt(e -> e.getKey().length());
public static Map<String, Integer> sortByValueThenByKey(Map<String, Integer> unsortMap) {
      return unsortMap.entrySet()
               .stream()
               .sorted(Map.Entry.<String, Integer>comparingByValue()
                       .thenComparingInt(e -> e.getKey().length()))
               .collect(Collectors.toMap(Map.Entry::getKey, 
                     Map.Entry::getValue,(oldValue, newValue) -> newValue, 
                             LinkedHashMap::new));
}
sort factors using sort() or order() in R

sort factors using sort() or order() in R


By : user3605324
Date : March 29 2020, 07:55 AM
I hope this helps you . Since otu1id column is factor you cannot order them directly.
For example, observe the levels of data.
code :
factor(as.character(1:10))
# [1] 1  2  3  4  5  6  7  8  9  10
#Levels: 1 10 2 3 4 5 6 7 8 9
df[order(as.numeric(sub("_", "", df$otu1id))), ]
#OR
#df[order(as.numeric(sub("\\D", "", df$otu1id))), ]

#   taxonomy_y otu1id     taxonomy_x otu2id otu2 otu1
#1   Alistipes     _1      Roseburia    _29  333   16
#2   Alistipes     _1   Turicibacter    _63  241  119
#3   Alistipes     _1 Parasutterella    _37   14   90
#9   Alistipes     _2    Clostridium    _12  155   16
#4   Alistipes    _10          Dorea    _98   56   16
#5   Alistipes    _10    Clostridium    _10  178   16
#6   Alistipes    _10    Clostridium    _12  155   16
#10  Alistipes    _23   ClostridiumS    _12  155   16
#7   Alistipes   _100    Clostridium    _12  155   16
#8   Alistipes  _1008    Clostridium    _12  155   16
df[gtools::mixedorder(as.character(df$otu1id)), ]
df <- structure(list(taxonomy_y = structure(c(1L, 1L, 1L, 1L, 1L, 1L, 
1L, 1L, 1L, 1L), .Label = "Alistipes", class = "factor"), otu1id = structure(c(1L, 
1L, 1L, 2L, 2L, 2L, 3L, 4L, 5L, 6L), .Label = c("_1", "_10", 
"_100", "_1008", "_2", "_23"), class = "factor"), taxonomy_x = structure(c(5L, 
6L, 4L, 3L, 1L, 1L, 1L, 1L, 1L, 2L), .Label = c("Clostridium", 
"ClostridiumS", "Dorea", "Parasutterella", "Roseburia", "Turicibacter"
), class = "factor"), otu2id = structure(c(3L, 5L, 4L, 6L, 1L, 
2L, 2L, 2L, 2L, 2L), .Label = c("_10", "_12", "_29", "_37", "_63", 
"_98"), class = "factor"), otu2 = c(333L, 241L, 14L, 56L, 178L, 
155L, 155L, 155L, 155L, 155L), otu1 = c(16L, 119L, 90L, 16L, 
16L, 16L, 16L, 16L, 16L, 16L)), class = "data.frame", row.names = c("1", 
"2", "3", "4", "5", "6", "7", "8", "9", "10"))
Related Posts Related Posts :
  • Forcefully terminating a thread I didn't write in Java
  • Issue with ojdbc jar in Maven
  • String array length java
  • Java basic compilation error
  • Inquiry about writing a Char via ByteBuffer
  • Getting unexpected results when type casting between long and double
  • Variable throws variable might not have been initialized error
  • Start/stop java application from an external script
  • Confusion in declaring String Objects
  • What are some ways to do multi-core programming on Android, not just multi-thread?
  • hibernate - process scoped identity
  • Null Pointer Exception on getGraphics()
  • Can we print a java message on console without using main method, static variable and static method?
  • sending text from editText to ListView (2 activities)
  • Transfer value from JList to another class in Java
  • Creating 2 streams with one socket
  • How measure time stolen from virtual machine, in Scala/Java?
  • How can I programmatically generate keypress events?
  • org.apache.commons.net.ssh documentation
  • Implementation of Dijkstra`s Algorithm - Stuck in an infinite loop
  • Should I throw IllegalArgmentException when 'user of given id not exist'?
  • In Nimbus, how to paint TextField when MouseOver?
  • why won't checkforWin(File f) return true when it is true?
  • Android: Cursor is always returning null even if the database is not empty
  • Repeating for loop in menu
  • Can Java garbage collector randomly delete objects in the On-Heap tier?
  • Apache CXF Exception: SSL connection unexpectedly closed
  • Add properties to ArrayList<Object> in Java
  • Multiple Adapters or One Adapter for different lists and objects - Code Performance
  • Is it good practice in Java for a class's method to redundantly return a modified global field of the class?
  • How to change the color of the background in libgdx labels?
  • direct file path not working
  • ClassFileTransformer + Javassist: no such field
  • How do I change and instance variable for an object which the user selects from a combobox?
  • reading and updating a large xml file in java
  • ActionListener and Thread.sleep
  • What is the maximum of number of arguments for varargs in java?
  • When I compile I get an error as "ask" cannot be resolved or is not a field"
  • What is the best way to check if 4 integer variables are equal to 0?
  • Storing constant webdriver elements in an enum
  • Java: Why main class does not extend Thread class
  • Java - how to find out if a directory is being used by another process?
  • How can I get a method to print?
  • Java unknown exceptions
  • BufferedReader,StreamWriter crash
  • found raw type: JComboBox
  • Java Generics -> Function return type
  • how to refresh contents of jtable on event of action listener?
  • Why does List interface extend Collection interface?
  • Pros and Cons of Clojure http client libraries
  • use final inside a for each loop
  • Convert java data object to service object
  • Unsupported major.minor version 51.0 while executing JSP
  • How do I display a word diagonally in Java?
  • making sure one task completes before another starts in java
  • My program gives an index out of bounds error
  • Removing duplicate characters in a String (user inputted keyword)
  • Jersey 2.0 Content-Length not set
  • AWS.SimpleQueueService.NonExistentQueue Exception thrown when Accessing Existing SQS queue
  • Where can I find the source code for the com.sun.jdi package?
  • shadow
    Privacy Policy - Terms - Contact Us © ourworld-yourmove.org