[R] Unique Ordering

Patzelt, Edward patzelt at g.harvard.edu
Fri Apr 22 20:08:26 CEST 2016


Hi R-Help,

data at bottom

I've been struggling with a problem where I need to order based on 1) the
Frequency "Freq" and 2) keeping each group of 3 of the same type together
"Var2" but I want across all groups it to go "high to low" based on the
earn factor.

Thank you!

structure(list(Var1 = structure(c(1L, 3L, 2L, 1L, 2L, 3L, 1L,
3L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 1L, 3L, 2L, 1L, 3L, 2L, 1L, 2L,
3L, 3L, 1L, 2L, 3L, 1L, 2L, 1L, 2L, 3L, 3L, 1L, 2L, 3L, 1L, 2L,
1L, 3L, 2L, 1L, 3L, 2L, 1L, 2L, 3L, 1L, 3L, 2L, 1L, 3L, 2L, 1L,
2L, 3L, 3L, 1L, 2L, 3L, 1L, 2L, 1L, 3L, 2L, 3L, 1L, 2L, 1L, 2L,
3L, 3L, 1L, 2L, 1L, 3L, 2L, 3L, 1L, 2L, 1L, 2L, 3L, 3L, 1L, 2L,
1L, 3L, 2L, 1L, 3L, 2L, 1L, 3L, 2L, 3L, 1L, 2L, 1L, 3L, 2L, 1L,
3L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 1L, 3L,
2L, 3L, 1L, 2L, 1L, 2L, 3L, 1L, 2L, 3L, 3L, 2L, 1L, 3L, 1L, 2L,
3L, 1L, 2L, 1L, 3L, 2L, 3L, 1L, 2L, 1L, 2L, 3L, 3L, 1L, 2L, 3L,
1L, 2L, 1L, 3L, 2L, 1L, 2L, 3L, 1L, 3L, 2L, 3L, 1L, 2L, 3L, 1L,
2L, 3L, 1L, 2L, 1L, 3L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 1L, 2L, 3L,
3L, 1L, 2L, 3L, 1L, 2L, 1L, 2L, 3L, 3L, 1L, 2L, 3L, 1L, 2L, 3L,
1L, 2L, 3L, 1L, 2L, 1L, 2L, 3L, 3L, 1L, 2L, 1L, 2L, 3L, 3L, 1L,
2L, 3L, 1L, 2L, 1L, 3L, 2L, 1L, 3L, 2L, 1L, 3L, 2L, 1L, 2L, 3L,
1L, 2L, 3L, 1L, 2L, 3L, 1L, 3L, 2L, 1L, 2L, 3L, 1L, 3L, 2L, 1L,
2L, 3L, 1L, 3L, 2L, 3L, 1L, 2L, 3L, 1L, 2L, 1L, 3L, 2L, 3L, 1L,
2L, 1L, 2L, 3L), .Label = c("bank", "missed", "steal"), class = "factor"),
    Var2 = structure(c(89L, 89L, 89L, 88L, 88L, 88L, 87L, 87L,
    87L, 86L, 86L, 86L, 85L, 85L, 85L, 84L, 84L, 84L, 83L, 83L,
    83L, 82L, 82L, 82L, 81L, 81L, 81L, 80L, 80L, 80L, 79L, 79L,
    79L, 78L, 78L, 78L, 77L, 77L, 77L, 76L, 76L, 76L, 75L, 75L,
    75L, 74L, 74L, 74L, 73L, 73L, 73L, 72L, 72L, 72L, 71L, 71L,
    71L, 70L, 70L, 70L, 69L, 69L, 69L, 68L, 68L, 68L, 67L, 67L,
    67L, 66L, 66L, 66L, 65L, 65L, 65L, 64L, 64L, 64L, 63L, 63L,
    63L, 62L, 62L, 62L, 61L, 61L, 61L, 60L, 60L, 60L, 59L, 59L,
    59L, 58L, 58L, 58L, 57L, 57L, 57L, 56L, 56L, 56L, 55L, 55L,
    55L, 54L, 54L, 54L, 53L, 53L, 53L, 52L, 52L, 52L, 51L, 51L,
    51L, 50L, 50L, 50L, 49L, 49L, 49L, 48L, 48L, 48L, 47L, 47L,
    47L, 46L, 46L, 46L, 45L, 45L, 45L, 44L, 44L, 44L, 43L, 43L,
    43L, 42L, 42L, 42L, 41L, 41L, 41L, 40L, 40L, 40L, 39L, 39L,
    39L, 38L, 38L, 38L, 37L, 37L, 37L, 36L, 36L, 36L, 35L, 35L,
    35L, 34L, 34L, 34L, 33L, 33L, 33L, 32L, 32L, 32L, 31L, 31L,
    31L, 30L, 30L, 30L, 29L, 29L, 29L, 28L, 28L, 28L, 27L, 27L,
    27L, 26L, 26L, 26L, 25L, 25L, 25L, 24L, 24L, 24L, 23L, 23L,
    23L, 22L, 22L, 22L, 21L, 21L, 21L, 20L, 20L, 20L, 19L, 19L,
    19L, 18L, 18L, 18L, 17L, 17L, 17L, 16L, 16L, 16L, 15L, 15L,
    15L, 14L, 14L, 14L, 13L, 13L, 13L, 12L, 12L, 12L, 11L, 11L,
    11L, 10L, 10L, 10L, 9L, 9L, 9L, 8L, 8L, 8L, 7L, 7L, 7L, 6L,
    6L, 6L, 5L, 5L, 5L, 4L, 4L, 4L, 3L, 3L, 3L, 2L, 2L, 2L, 1L,
    1L, 1L), .Label = c("PROCS001", "PROCS002", "PROCS003", "PROCS004",
    "PROCS006", "PROCS007", "PROCS008", "PROCS009", "PROCS010",
    "PROCS011", "PROCS012", "PROCS013", "PROCS014", "PROCS016",
    "PROCS017", "PROCS019", "PROCS020", "PROC009", "PROC010",
    "PROC012", "PROC013", "PROC014", "PROC015", "PROC016", "PROC017",
    "PROC018", "PROC019", "PROC020", "PROC021", "PROC024", "PROC025",
    "PROC026", "PROC028", "PROC030", "PROC032", "PROA001", "PROA002",
    "PROA003", "PROA006", "PROA007", "PROA008", "PROA009", "PROA010",
    "PROA011", "PROA012", "PROA013", "PROA014", "PROA015", "PROA016",
    "PROA018", "PROA019", "PROA020", "PROA021", "PROA022", "PRO013",
    "PRO016", "PRO017", "PRO018", "PRO019", "PRO020", "PRO021",
    "PRO022", "PRO024", "PRO027", "PRO028", "PRO029", "PRO030",
    "PRO032", "PRO033", "PRO034", "PRO035", "PRO037", "PRO038",
    "PRO039", "PRO040", "PRO041", "PRO042", "PRO044", "PRO045",
    "PRO047", "PRO048", "PRO049", "PRO050", "PRO051", "PRO052",
    "PRO053", "PRO056", "PRO057", "PRO058"), class = "factor"),
    Freq = c(71L, 9L, 0L, 80L, 0L, 0L, 63L, 17L, 0L, 80L, 0L,
    0L, 53L, 27L, 0L, 74L, 6L, 0L, 40L, 40L, 0L, 80L, 0L, 0L,
    66L, 14L, 0L, 80L, 0L, 0L, 80L, 0L, 0L, 60L, 20L, 0L, 68L,
    12L, 0L, 61L, 18L, 1L, 56L, 24L, 0L, 80L, 0L, 0L, 40L, 40L,
    0L, 46L, 34L, 0L, 80L, 0L, 0L, 57L, 23L, 0L, 77L, 2L, 1L,
    78L, 2L, 0L, 56L, 24L, 0L, 80L, 0L, 0L, 79L, 1L, 0L, 73L,
    7L, 0L, 73L, 7L, 0L, 80L, 0L, 0L, 79L, 1L, 0L, 52L, 28L,
    0L, 53L, 27L, 0L, 53L, 26L, 1L, 55L, 25L, 0L, 70L, 9L, 1L,
    66L, 14L, 0L, 50L, 30L, 0L, 46L, 34L, 0L, 80L, 0L, 0L, 71L,
    9L, 0L, 62L, 18L, 0L, 73L, 7L, 0L, 80L, 0L, 0L, 80L, 0L,
    0L, 79L, 1L, 0L, 77L, 3L, 0L, 59L, 21L, 0L, 41L, 39L, 0L,
    74L, 6L, 0L, 80L, 0L, 0L, 59L, 21L, 0L, 74L, 6L, 0L, 78L,
    2L, 0L, 80L, 0L, 0L, 74L, 6L, 0L, 80L, 0L, 0L, 80L, 0L, 0L,
    80L, 0L, 0L, 79L, 1L, 0L, 66L, 14L, 0L, 80L, 0L, 0L, 80L,
    0L, 0L, 80L, 0L, 0L, 80L, 0L, 0L, 80L, 0L, 0L, 72L, 8L, 0L,
    80L, 0L, 0L, 69L, 11L, 0L, 80L, 0L, 0L, 80L, 0L, 0L, 79L,
    1L, 0L, 80L, 0L, 0L, 64L, 16L, 0L, 75L, 0L, 0L, 67L, 8L,
    0L, 68L, 7L, 0L, 73L, 2L, 0L, 75L, 0L, 0L, 75L, 0L, 0L, 75L,
    0L, 0L, 44L, 30L, 1L, 75L, 0L, 0L, 42L, 33L, 0L, 75L, 0L,
    0L, 42L, 33L, 0L, 45L, 30L, 0L, 67L, 8L, 0L, 51L, 24L, 0L,
    58L, 17L, 0L, 75L, 0L, 0L)), .Names = c("Var1", "Var2", "Freq"
), row.names = c(265L, 267L, 266L, 262L, 263L, 264L, 259L, 261L,
260L, 258L, 256L, 257L, 255L, 253L, 254L, 250L, 252L, 251L, 247L,
249L, 248L, 244L, 245L, 246L, 243L, 241L, 242L, 240L, 238L, 239L,
235L, 236L, 237L, 234L, 232L, 233L, 231L, 229L, 230L, 226L, 228L,
227L, 223L, 225L, 224L, 220L, 221L, 222L, 217L, 219L, 218L, 214L,
216L, 215L, 211L, 212L, 213L, 210L, 208L, 209L, 207L, 205L, 206L,
202L, 204L, 203L, 201L, 199L, 200L, 196L, 197L, 198L, 195L, 193L,
194L, 190L, 192L, 191L, 189L, 187L, 188L, 184L, 185L, 186L, 183L,
181L, 182L, 178L, 180L, 179L, 175L, 177L, 176L, 172L, 174L, 173L,
171L, 169L, 170L, 166L, 168L, 167L, 163L, 165L, 164L, 162L, 160L,
161L, 159L, 157L, 158L, 156L, 154L, 155L, 153L, 151L, 152L, 148L,
150L, 149L, 147L, 145L, 146L, 142L, 143L, 144L, 139L, 140L, 141L,
138L, 137L, 136L, 135L, 133L, 134L, 132L, 130L, 131L, 127L, 129L,
128L, 126L, 124L, 125L, 121L, 122L, 123L, 120L, 118L, 119L, 117L,
115L, 116L, 112L, 114L, 113L, 109L, 110L, 111L, 106L, 108L, 107L,
105L, 103L, 104L, 102L, 100L, 101L, 99L, 97L, 98L, 94L, 96L,
95L, 93L, 91L, 92L, 90L, 88L, 89L, 85L, 86L, 87L, 84L, 82L, 83L,
81L, 79L, 80L, 76L, 77L, 78L, 75L, 73L, 74L, 72L, 70L, 71L, 69L,
67L, 68L, 66L, 64L, 65L, 61L, 62L, 63L, 60L, 58L, 59L, 55L, 56L,
57L, 54L, 52L, 53L, 51L, 49L, 50L, 46L, 48L, 47L, 43L, 45L, 44L,
40L, 42L, 41L, 37L, 38L, 39L, 34L, 35L, 36L, 31L, 32L, 33L, 28L,
30L, 29L, 25L, 26L, 27L, 22L, 24L, 23L, 19L, 20L, 21L, 16L, 18L,
17L, 15L, 13L, 14L, 12L, 10L, 11L, 7L, 9L, 8L, 6L, 4L, 5L, 1L,
2L, 3L), class = "data.frame")



-- 
Edward H Patzelt | Clinical Science PhD Student
Psychology | Harvard University
Systems Neuroscience of Psychopathology Laboratory

	[[alternative HTML version deleted]]



More information about the R-help mailing list