How to create a table of age range in R - r

I have a dataframe from Alzheimer disease patients. I would like to create a table with counts for the number of patients (indicated by patient ID: iid) with age_at_onset <75, <70 for each status (1,2,3) per Ethnicity. How can I do this in R?
df <- structure(list(iid = structure(c(`5068` = 80L, `15562` = 58L,
`8939` = 52L, `17602` = 34L, `3173` = 40L, `12591` = 30L, `17391` = 97L,
`8241` = 93L, `9746` = 10L, `9673` = 7L, `16594` = 29L, `16911` = 60L,
`4796` = 18L, `6598` = 12L, `11462` = 26L, `16425` = 17L, `12698` = 37L,
`17118` = 81L, `1501` = 76L, `13294` = 92L, `8072` = 84L, `11642` = 46L,
`4164` = 85L, `9035` = 62L, `16691` = 35L, `16002` = 86L, `3915` = 21L,
`7409` = 54L, `9759` = 11L, `6130` = 6L, `15153` = 23L, `13539` = 100L,
`13262` = 87L, `742` = 28L, `17592` = 33L, `16812` = 53L, `213` = 66L,
`11963` = 77L, `12093` = 89L, `11910` = 68L, `15813` = 73L, `1104` = 51L,
`1966` = 95L, `5589` = 61L, `8860` = 41L, `482` = 16L, `3967` = 55L,
`5869` = 1L, `12435` = 20L, `11675` = 50L, `16701` = 36L, `5893` = 2L,
`16880` = 57L, `13290` = 90L, `1097` = 49L, `1476` = 71L, `9100` = 67L,
`6220` = 8L, `15393` = 42L, `16631` = 31L, `9641` = 4L, `13485` = 99L,
`1028` = 44L, `8200` = 91L, `12190` = 94L, `5581` = 19L, `7266` = 43L,
`12254` = 98L, `15763` = 69L, `17764` = 79L, `16239` = 96L, `7548` = 59L,
`12037` = 83L, `7813` = 70L, `12943` = 63L, `17748` = 75L, `12703` = 38L,
`11964` = 78L, `14018` = 45L, `1769` = 88L, `13713` = 22L, `13100` = 74L,
`13866` = 32L, `2527` = 25L, `2281` = 15L, `4463` = 39L, `5815` = 14L,
`14040` = 47L, `16560` = 24L, `12887` = 56L, `11167` = 13L, `6123` = 5L,
`5668` = 48L, `3036` = 82L, `7622` = 65L, `11470` = 27L, `4770` = 64L,
`17050` = 72L, `6295` = 9L, `9575` = 3L), .Label = c("08AD09051_NACC295883",
"08AD10766_NACC977458", "08AD9133", "09AD14006", "09AD14313_NACC904765",
"09AD14360_NACC785663", "09AD14874", "09AD14943_NACC009736",
"09AD15417_NACC169039", "09AD15778", "09AD15810", "09AD17022_NACC426380",
"25795", "NACC026302", "NACC026743", "NACC044624", "NACC062886",
"NACC083669", "NACC088187", "NACC094571", "NACC107551", "NACC134929",
"NACC178119", "NACC178349", "NACC183751", "NACC186606", "NACC192719",
"NACC193548", "NACC209758", "NACC224665", "NACC243923", "NACC246256",
"NACC261383", "NACC283729", "NACC298544", "NACC305567", "NACC310219",
"NACC310896", "NACC312856", "NACC336802", "NACC342957", "NACC350799",
"NACC351234_09AD13080", "NACC355338", "NACC355951", "NACC361682",
"NACC369873", "NACC397276", "NACC402765", "NACC403144", "NACC407162",
"NACC412031", "NACC413408", "NACC422516_08AD10849", "NACC436908",
"NACC465387", "NACC472288", "NACC479723", "NACC485644_08AD8204",
"NACC504120", "NACC508353", "NACC509594", "NACC510498", "NACC519864",
"NACC521718_08AD9198", "NACC559675", "NACC585997", "NACC605438",
"NACC612578", "NACC619036_09AD14621", "NACC621261", "NACC634809",
"NACC635885", "NACC639654", "NACC640099", "NACC642393", "NACC660918",
"NACC660981", "NACC684037", "NACC690933", "NACC695603", "NACC703758",
"NACC740374", "NACC744168_08AD7716", "NACC766835", "NACC769330",
"NACC775129", "NACC792439", "NACC796641", "NACC805995", "NACC806269_09AD13056",
"NACC809589", "NACC824113_08AD9038", "NACC884140", "NACC916661",
"NACC921664", "NACC926195", "NACC929277", "NACC959601", "NACC992086"
), class = "factor"), omit = structure(c(`5068` = 1L, `15562` = 1L,
`8939` = 1L, `17602` = 1L, `3173` = 1L, `12591` = 2L, `17391` = 1L,
`8241` = 1L, `9746` = 1L, `9673` = 2L, `16594` = 2L, `16911` = 2L,
`4796` = 1L, `6598` = 2L, `11462` = 1L, `16425` = 1L, `12698` = 1L,
`17118` = 1L, `1501` = 1L, `13294` = 1L, `8072` = 1L, `11642` = 2L,
`4164` = 1L, `9035` = 1L, `16691` = 1L, `16002` = 1L, `3915` = 1L,
`7409` = 1L, `9759` = 1L, `6130` = 1L, `15153` = 1L, `13539` = 2L,
`13262` = 1L, `742` = 2L, `17592` = 1L, `16812` = 1L, `213` = 2L,
`11963` = 2L, `12093` = 2L, `11910` = 2L, `15813` = 1L, `1104` = 1L,
`1966` = 1L, `5589` = 1L, `8860` = 1L, `482` = 1L, `3967` = 1L,
`5869` = 2L, `12435` = 1L, `11675` = 2L, `16701` = 1L, `5893` = 1L,
`16880` = 2L, `13290` = 2L, `1097` = 1L, `1476` = 1L, `9100` = 1L,
`6220` = 1L, `15393` = 1L, `16631` = 1L, `9641` = 1L, `13485` = 2L,
`1028` = 1L, `8200` = 2L, `12190` = 1L, `5581` = 2L, `7266` = 1L,
`12254` = 1L, `15763` = 1L, `17764` = 1L, `16239` = 1L, `7548` = 1L,
`12037` = 1L, `7813` = 1L, `12943` = 2L, `17748` = 1L, `12703` = 1L,
`11964` = 1L, `14018` = 1L, `1769` = 1L, `13713` = 1L, `13100` = 1L,
`13866` = 2L, `2527` = 1L, `2281` = 1L, `4463` = 1L, `5815` = 1L,
`14040` = 1L, `16560` = 2L, `12887` = 1L, `11167` = 2L, `6123` = 2L,
`5668` = 1L, `3036` = 1L, `7622` = 1L, `11470` = 1L, `4770` = 1L,
`17050` = 2L, `6295` = 2L, `9575` = 1L), .Label = c("0", "1"), class = "factor"),
sex = structure(c(1L, 1L, 1L, 2L, 1L, NA, 2L, 2L, 1L, NA,
2L, 2L, 1L, NA, 2L, 2L, 2L, 2L, 2L, 2L, 2L, NA, 2L, 1L, 1L,
2L, 2L, 2L, 1L, 1L, 2L, NA, 2L, 2L, 1L, 2L, 2L, NA, NA, NA,
2L, 1L, 2L, 1L, 1L, 2L, 2L, NA, 2L, NA, 1L, 2L, 1L, NA, 2L,
1L, 2L, 2L, 2L, 2L, 1L, NA, 2L, NA, 2L, 2L, 2L, 2L, 2L, 1L,
2L, 2L, 2L, 1L, NA, 2L, 2L, 1L, 2L, 1L, 1L, 2L, NA, 1L, 2L,
1L, 2L, 2L, 1L, 1L, NA, NA, 1L, 1L, 2L, 2L, 2L, 2L, NA, 2L
), .Label = c(" 1", " 2", "-9"), class = "factor"), status = structure(c(2L,
2L, 2L, 1L, 3L, NA, 2L, 2L, 2L, NA, 2L, NA, 1L, NA, 2L, 1L,
1L, 1L, 2L, 1L, 2L, NA, 3L, 2L, 1L, 1L, 1L, 2L, 2L, 1L, 1L,
NA, 1L, 2L, 2L, 2L, NA, NA, NA, NA, 2L, 1L, 1L, 3L, 2L, 1L,
3L, NA, 1L, NA, 2L, 1L, NA, NA, 1L, 2L, 2L, 1L, 1L, 1L, 2L,
NA, 1L, NA, 1L, 1L, 2L, 2L, 1L, 2L, 1L, 2L, 2L, 2L, NA, 1L,
1L, 2L, 2L, 2L, 1L, 1L, NA, 3L, 1L, 3L, 3L, 1L, NA, 2L, NA,
NA, 3L, 2L, 2L, 1L, 2L, 2L, NA, 2L), .Label = c(" 1", " 2",
" 3", "-9"), class = "factor"), age_at_onset = structure(c(`5068` = 4L,
`15562` = 16L, `8939` = 24L, `17602` = NA, `3173` = 24L,
`12591` = NA, `17391` = 15L, `8241` = 13L, `9746` = 18L,
`9673` = NA, `16594` = 20L, `16911` = NA, `4796` = NA, `6598` = NA,
`11462` = 20L, `16425` = NA, `12698` = NA, `17118` = NA,
`1501` = 5L, `13294` = NA, `8072` = 11L, `11642` = NA, `4164` = 25L,
`9035` = NA, `16691` = NA, `16002` = NA, `3915` = NA, `7409` = 21L,
`9759` = 14L, `6130` = NA, `15153` = NA, `13539` = NA, `13262` = NA,
`742` = 26L, `17592` = 28L, `16812` = 9L, `213` = 14L, `11963` = NA,
`12093` = NA, `11910` = NA, `15813` = 10L, `1104` = NA, `1966` = NA,
`5589` = 16L, `8860` = 8L, `482` = NA, `3967` = 7L, `5869` = NA,
`12435` = NA, `11675` = NA, `16701` = 19L, `5893` = NA, `16880` = 22L,
`13290` = NA, `1097` = NA, `1476` = 7L, `9100` = 22L, `6220` = NA,
`15393` = NA, `16631` = NA, `9641` = NA, `13485` = NA, `1028` = NA,
`8200` = NA, `12190` = NA, `5581` = NA, `7266` = 17L, `12254` = 17L,
`15763` = NA, `17764` = 6L, `16239` = NA, `7548` = 14L, `12037` = 27L,
`7813` = 26L, `12943` = NA, `17748` = NA, `12703` = NA, `11964` = 20L,
`14018` = 23L, `1769` = 25L, `13713` = NA, `13100` = NA,
`13866` = NA, `2527` = 12L, `2281` = NA, `4463` = 1L, `5815` = 3L,
`14040` = NA, `16560` = NA, `12887` = 14L, `11167` = NA,
`6123` = NA, `5668` = 5L, `3036` = 2L, `7622` = 7L, `11470` = NA,
`4770` = 17L, `17050` = 15L, `6295` = NA, `9575` = 19L), .Label = c("44",
"52", "56", "58", "60", "61", "62", "64", "65", "66", "67",
"69", "70", "71", "72", "73", "74", "75", "76", "77", "78",
"79", "80", "81", "82", "83", "88", "90"), class = "factor"),
age_last_visit = structure(c(`5068` = 8L, `15562` = 18L,
`8939` = 24L, `17602` = 16L, `3173` = 21L, `12591` = NA,
`17391` = 17L, `8241` = NA, `9746` = NA, `9673` = NA, `16594` = 25L,
`16911` = 4L, `4796` = 5L, `6598` = NA, `11462` = 21L, `16425` = 10L,
`12698` = 25L, `17118` = 12L, `1501` = 7L, `13294` = 9L,
`8072` = NA, `11642` = NA, `4164` = 21L, `9035` = 21L, `16691` = 3L,
`16002` = 14L, `3915` = 13L, `7409` = NA, `9759` = NA, `6130` = 25L,
`15153` = 22L, `13539` = NA, `13262` = 24L, `742` = 26L,
`17592` = 30L, `16812` = 9L, `213` = 11L, `11963` = NA, `12093` = NA,
`11910` = NA, `15813` = 10L, `1104` = 24L, `1966` = 14L,
`5589` = 18L, `8860` = 23L, `482` = 15L, `3967` = 7L, `5869` = NA,
`12435` = 6L, `11675` = NA, `16701` = 25L, `5893` = NA, `16880` = 20L,
`13290` = NA, `1097` = 8L, `1476` = 5L, `9100` = 28L, `6220` = 21L,
`15393` = 17L, `16631` = 9L, `9641` = 24L, `13485` = NA,
`1028` = 7L, `8200` = NA, `12190` = 8L, `5581` = 15L, `7266` = NA,
`12254` = 19L, `15763` = 7L, `17764` = 6L, `16239` = 11L,
`7548` = NA, `12037` = 29L, `7813` = NA, `12943` = NA, `17748` = 23L,
`12703` = 27L, `11964` = 23L, `14018` = 26L, `1769` = 24L,
`13713` = 13L, `13100` = 20L, `13866` = NA, `2527` = 13L,
`2281` = 21L, `4463` = 4L, `5815` = 3L, `14040` = 2L, `16560` = 14L,
`12887` = 24L, `11167` = NA, `6123` = NA, `5668` = 12L, `3036` = 1L,
`7622` = NA, `11470` = 18L, `4770` = 18L, `17050` = 18L,
`6295` = NA, `9575` = NA), .Label = c("59", "60", "61", "62",
"64", "65", "67", "68", "69", "70", "71", "72", "73", "74",
"75", "76", "77", "79", "80", "81", "82", "83", "84", "85",
"86", "89", "91", "92", "93", "94"), class = "factor"), age_at_death = structure(c(`5068` = 2L,
`15562` = NA, `8939` = NA, `17602` = NA, `3173` = NA, `12591` = NA,
`17391` = NA, `8241` = 10L, `9746` = 9L, `9673` = NA, `16594` = NA,
`16911` = NA, `4796` = NA, `6598` = NA, `11462` = NA, `16425` = NA,
`12698` = NA, `17118` = NA, `1501` = NA, `13294` = NA, `8072` = 6L,
`11642` = NA, `4164` = NA, `9035` = NA, `16691` = NA, `16002` = NA,
`3915` = NA, `7409` = 16L, `9759` = 8L, `6130` = NA, `15153` = NA,
`13539` = NA, `13262` = NA, `742` = 14L, `17592` = NA, `16812` = NA,
`213` = NA, `11963` = NA, `12093` = NA, `11910` = NA, `15813` = NA,
`1104` = NA, `1966` = NA, `5589` = NA, `8860` = NA, `482` = NA,
`3967` = NA, `5869` = NA, `12435` = NA, `11675` = NA, `16701` = NA,
`5893` = 16L, `16880` = NA, `13290` = NA, `1097` = NA, `1476` = 1L,
`9100` = NA, `6220` = NA, `15393` = NA, `16631` = NA, `9641` = NA,
`13485` = NA, `1028` = NA, `8200` = NA, `12190` = NA, `5581` = NA,
`7266` = 11L, `12254` = NA, `15763` = NA, `17764` = 3L, `16239` = NA,
`7548` = 6L, `12037` = 15L, `7813` = 13L, `12943` = NA, `17748` = NA,
`12703` = NA, `11964` = NA, `14018` = NA, `1769` = 12L, `13713` = NA,
`13100` = NA, `13866` = NA, `2527` = 5L, `2281` = NA, `4463` = NA,
`5815` = NA, `14040` = NA, `16560` = NA, `12887` = NA, `11167` = NA,
`6123` = NA, `5668` = NA, `3036` = NA, `7622` = 4L, `11470` = NA,
`4770` = NA, `17050` = NA, `6295` = NA, `9575` = 7L), .Label = c("66",
"70", "71", "73", "74", "75", "77", "79", "82", "83", "85",
"86", "88", "90", "93", "94"), class = "factor"), aaoaae = structure(c(3L,
16L, 24L, 19L, 25L, NA, 15L, 13L, 18L, NA, 20L, 6L, 7L, NA,
20L, 13L, 29L, 15L, 4L, 12L, 10L, NA, 25L, NA, 5L, 17L, 16L,
21L, 14L, 29L, 26L, NA, 28L, 26L, 31L, 8L, 14L, NA, NA, NA,
9L, 28L, 17L, 22L, 7L, 18L, 10L, NA, 8L, NA, 19L, 33L, 24L,
NA, 11L, 6L, 22L, 25L, 20L, 12L, NA, NA, 10L, NA, 11L, 18L,
17L, 17L, 10L, 5L, 14L, 14L, 30L, 26L, NA, 27L, 32L, 20L,
23L, 25L, 16L, 24L, NA, 16L, 25L, 6L, 5L, 4L, 17L, 14L, NA,
NA, 15L, 2L, 6L, 22L, 17L, 15L, NA, 19L), .Label = c("-9",
"52", "58", "60", "61", "62", "64", "65", "66", "67", "68",
"69", "70", "71", "72", "73", "74", "75", "76", "77", "78",
"79", "80", "81", "82", "83", "84", "85", "86", "88", "90",
"91", "94"), class = "factor"), aaoaae2 = structure(c(3L,
16L, 24L, 19L, 25L, NA, 15L, 13L, 18L, NA, 20L, 6L, 7L, NA,
20L, 13L, 29L, 15L, 4L, 12L, 10L, NA, 25L, NA, 5L, 17L, 16L,
21L, 14L, 29L, 26L, NA, 28L, 26L, 31L, 8L, 14L, NA, NA, NA,
9L, 28L, 17L, 22L, 7L, 18L, 10L, NA, 8L, NA, 19L, 33L, 24L,
NA, 11L, 6L, 22L, 25L, 20L, 12L, NA, NA, 10L, NA, 11L, 18L,
17L, 17L, 10L, 5L, 14L, 14L, 30L, 26L, NA, 27L, 32L, 20L,
23L, 25L, 16L, 24L, NA, 16L, 25L, 6L, 5L, 4L, 17L, 14L, NA,
NA, 15L, 2L, 6L, 22L, 17L, 15L, NA, 19L), .Label = c("-9",
"52", "58", "60", "61", "62", "64", "65", "66", "67", "68",
"69", "70", "71", "72", "73", "74", "75", "76", "77", "78",
"79", "80", "81", "82", "83", "84", "85", "86", "88", "90",
"91", "94"), class = "factor"), apoe_1 = structure(c(3L,
3L, 3L, 3L, 3L, NA, 3L, 3L, 3L, NA, 3L, 2L, 3L, NA, 3L, 2L,
3L, 4L, 4L, 3L, 3L, NA, 4L, 3L, 3L, 3L, 3L, 3L, 3L, NA, 2L,
NA, 3L, 3L, 2L, 4L, 4L, NA, NA, NA, 4L, 3L, 4L, 2L, NA, 3L,
4L, NA, 3L, NA, 4L, 3L, 2L, NA, 4L, 3L, 3L, 3L, 3L, 3L, 3L,
NA, 3L, NA, 4L, 3L, 3L, 3L, 3L, 4L, 3L, 3L, 3L, 3L, NA, 3L,
3L, 4L, 3L, 3L, 3L, 3L, NA, 3L, 3L, 3L, 3L, 3L, 3L, 3L, NA,
NA, 3L, 3L, 3L, 3L, 3L, 4L, NA, 4L), .Label = c("-9", "2",
"3", "4"), class = "factor"), apoe_2 = structure(c(4L, 4L,
3L, 3L, 3L, NA, 4L, 4L, 4L, NA, 3L, 3L, 3L, NA, 4L, 3L, 3L,
4L, 4L, 3L, 4L, NA, 2L, 4L, 3L, 4L, 3L, 4L, 3L, NA, 3L, NA,
3L, 3L, 3L, 4L, 2L, NA, NA, NA, 2L, 3L, 3L, 3L, NA, 3L, 3L,
NA, 3L, NA, 3L, 3L, 2L, NA, 3L, 4L, 4L, 4L, 3L, 4L, 4L, NA,
4L, NA, 2L, 3L, 3L, 3L, 4L, 3L, 2L, 4L, 4L, 3L, NA, 3L, 3L,
4L, 3L, 3L, 4L, 3L, NA, 3L, 3L, 2L, 3L, 2L, 3L, 4L, NA, NA,
2L, 4L, 3L, 4L, 2L, 3L, NA, 4L), .Label = c("-9", "2", "3",
"4"), class = "factor"), apoe4any = structure(c(3L, 3L, 2L,
2L, 2L, NA, 3L, 3L, 3L, NA, 2L, 2L, 2L, NA, 3L, 2L, 2L, 3L,
3L, 2L, 3L, NA, 3L, 3L, 2L, 3L, 2L, 3L, 2L, NA, 2L, NA, 2L,
2L, 2L, 3L, 3L, NA, NA, NA, 3L, 2L, 3L, 2L, NA, 2L, 3L, NA,
2L, NA, 3L, 2L, 2L, NA, 3L, 3L, 3L, 3L, 2L, 3L, 3L, NA, 3L,
NA, 3L, 2L, 2L, 2L, 3L, 3L, 2L, 3L, 3L, 2L, NA, 2L, 2L, 3L,
2L, 2L, 3L, 2L, NA, 2L, 2L, 2L, 2L, 2L, 2L, 3L, NA, NA, 2L,
3L, 2L, 3L, 2L, 3L, NA, 3L), .Label = c("-9", "0", "1"), class = "factor"),
apoe4dose = structure(c(3L, 3L, 2L, 2L, 2L, NA, 3L, 3L, 3L,
NA, 2L, 2L, 2L, NA, 3L, 2L, 2L, 4L, 4L, 2L, 3L, NA, 3L, 3L,
2L, 3L, 2L, 3L, 2L, NA, 2L, NA, 2L, 2L, 2L, 4L, 3L, NA, NA,
NA, 3L, 2L, 3L, 2L, NA, 2L, 3L, NA, 2L, NA, 3L, 2L, 2L, NA,
3L, 3L, 3L, 3L, 2L, 3L, 3L, NA, 3L, NA, 3L, 2L, 2L, 2L, 3L,
3L, 2L, 3L, 3L, 2L, NA, 2L, 2L, 4L, 2L, 2L, 3L, 2L, NA, 2L,
2L, 2L, 2L, 2L, 2L, 3L, NA, NA, 2L, 3L, 2L, 3L, 2L, 3L, NA,
4L), .Label = c("-9", "0", "1", "2"), class = "factor"),
Ethnicity = structure(c(`5068` = 4L, `15562` = 4L, `8939` = 4L,
`17602` = 3L, `3173` = 4L, `12591` = 4L, `17391` = 4L, `8241` = 4L,
`9746` = 4L, `9673` = 4L, `16594` = 4L, `16911` = 4L, `4796` = 4L,
`6598` = 4L, `11462` = 4L, `16425` = 4L, `12698` = 4L, `17118` = 4L,
`1501` = 4L, `13294` = 4L, `8072` = 4L, `11642` = 4L, `4164` = 1L,
`9035` = 4L, `16691` = 4L, `16002` = 4L, `3915` = 2L, `7409` = 4L,
`9759` = 4L, `6130` = 4L, `15153` = 4L, `13539` = 4L, `13262` = 4L,
`742` = 4L, `17592` = 3L, `16812` = 4L, `213` = 1L, `11963` = 4L,
`12093` = 4L, `11910` = 4L, `15813` = 4L, `1104` = 4L, `1966` = 4L,
`5589` = 1L, `8860` = 4L, `482` = 4L, `3967` = 4L, `5869` = 4L,
`12435` = 4L, `11675` = 4L, `16701` = 4L, `5893` = 4L, `16880` = 4L,
`13290` = 4L, `1097` = 4L, `1476` = 4L, `9100` = 4L, `6220` = 4L,
`15393` = 4L, `16631` = 4L, `9641` = 4L, `13485` = 4L, `1028` = 4L,
`8200` = 4L, `12190` = 4L, `5581` = 4L, `7266` = 4L, `12254` = 4L,
`15763` = 4L, `17764` = 3L, `16239` = 4L, `7548` = 4L, `12037` = 4L,
`7813` = 4L, `12943` = 4L, `17748` = 3L, `12703` = 4L, `11964` = 4L,
`14018` = 4L, `1769` = 4L, `13713` = 4L, `13100` = 4L, `13866` = 4L,
`2527` = 4L, `2281` = 2L, `4463` = 4L, `5815` = 4L, `14040` = 4L,
`16560` = 4L, `12887` = 4L, `11167` = 4L, `6123` = 4L, `5668` = 4L,
`3036` = 4L, `7622` = 4L, `11470` = 4L, `4770` = 2L, `17050` = 4L,
`6295` = 4L, `9575` = 4L), .Label = c("AA", "Asian", "Hispanic",
"NHW"), class = "factor")), row.names = c(NA, -100L), class = "data.frame")

We can do a group by 'status', 'Ethnicity' and get the sum of logical vector
library(dplyr)
df %>%
group_by(status, Ethnicity) %>%
summarise(n_75 = sum(as.numeric(as.character(age_at_onset)) < 75,
na.rm = TRUE),
n_70= sum(as.numeric(as.character(age_at_onset)) < 70,
na.rm = TRUE) )
-output
# A tibble: 10 x 4
# Groups: status [4]
# status Ethnicity n_75 n_70
# <fct> <fct> <int> <int>
# 1 " 1" Asian 0 0
# 2 " 1" Hispanic 0 0
# 3 " 1" NHW 0 0
# 4 " 2" Asian 1 0
# 5 " 2" Hispanic 1 1
# 6 " 2" NHW 18 9
# 7 " 3" AA 1 0
# 8 " 3" NHW 5 5
# 9 <NA> AA 1 0
#10 <NA> NHW 0 0

This is work:
> df %>% select(iid, age_at_onset, status, Ethnicity) %>%
+ mutate(LT75 = ifelse(as.numeric(as.character(df$age_at_onset)) < 75, 1,0), LT70 = ifelse(as.numeric(as.character(df$age_at_onset)) < 70, 1,0)) %>% group_by(status, Ethnicity) %>%
+ summarise(Lessthan75 = sum(LT75, na.rm = 1), Lessthan70 = sum(LT70, na.rm = 1))
`summarise()` regrouping output by 'status' (override with `.groups` argument)
# A tibble: 10 x 4
# Groups: status [4]
status Ethnicity Lessthan75 Lessthan70
<fct> <fct> <dbl> <dbl>
1 " 1" Asian 0 0
2 " 1" Hispanic 0 0
3 " 1" NHW 0 0
4 " 2" Asian 1 0
5 " 2" Hispanic 1 1
6 " 2" NHW 18 9
7 " 3" AA 1 0
8 " 3" NHW 5 5
9 NA AA 1 0
10 NA NHW 0 0
>

You have age_at_onset as factor, convert it to numeric, then use cut to divide data into different buckets and count to count how many iid fall into each bucket.
library(dplyr)
df %>%
mutate(age_at_onset = as.numeric(as.character(age_at_onset)),
age_group = cut(age_at_onset, c(-Inf, 70, 75, Inf))) %>%
count(Ethnicity, status, age_group)
# Ethnicity status age_group n
#1 AA 3 (70,75] 1
#2 AA 3 (75, Inf] 1
#3 AA <NA> (70,75] 1
#4 Asian 1 <NA> 2
#5 Asian 2 (70,75] 1
#6 Hispanic 1 <NA> 2
#7 Hispanic 2 (-Inf,70] 1
#8 Hispanic 2 (75, Inf] 1
#9 NHW 1 <NA> 29
#10 NHW 2 (-Inf,70] 10
#11 NHW 2 (70,75] 9
#12 NHW 2 (75, Inf] 13
#13 NHW 2 <NA> 2
#14 NHW 3 (-Inf,70] 5
#15 NHW 3 (75, Inf] 1
#16 NHW <NA> (75, Inf] 1
#17 NHW <NA> <NA> 20
If needed you can drop the NA values in age_group column with filter(!is.na(age_group)).

Related

Margins package in R generating NAs in results

This is my first post, so hopefully I'm doing this right.
I'm running a polr model in R and am attempting to generate some marginal effects plots using the margins package. When I view the results, everything except for the AME has a value of NA. Can anyone help me figure out what I'm doing wrong?
Here's a copy of my results:
factor AME SE z p lower upper
Gender -0.0452 NA NA NA NA NA
IsNonwhite 0.0087 NA NA NA NA NA
PartyNumeric 0.1898 NA NA NA NA NA
PartyStrength -0.0358 NA NA NA NA NA
And here's a copy of my code:
debate <- debate %>%
mutate(UnfairIndex = as.numeric((debate$UnfairCountTrump-debate$UnfairCountBiden)))
debate<- debate%>%
mutate(AbsUnfairIndex = abs(debate$UnfairIndex))
debate <- debate %>%
mutate(X7PartyScale=case_when(debate$StrongRep ==1 ~ 3,
debate$StrongRep ==2 ~ 2,
debate$StrongDem ==1 ~ -3,
debate$StrongDem ==2 ~ -2,
debate$IndCloser ==1 ~ 1,
debate$IndCloser ==2 ~ -1,
debate$IndCloser ==3 ~ 0))
debate<- debate %>%
mutate(PartyFactor=as.factor(case_when(debate$X7PartyScale==-3 ~ "Democrat",
debate$X7PartyScale==-2 ~ "Democrat",
debate$X7PartyScale==-1 ~ "Democrat",
debate$X7PartyScale==0 ~ "Independent",
debate$X7PartyScale==1 ~ "Republican",
debate$X7PartyScale==2 ~ "Republican",
debate$X7PartyScale==3 ~ "Republican")))
debate<- debate %>%
mutate(PartyStrength= abs(debate$X7PartyScale))
debate<- debate %>%
mutate(PartyNumeric = as.numeric(PartyFactor) - 1)
interact<- polr(factor(AbsUnfairIndex) ~ PartyStrength + PartyNumeric + PartyStrength*PartyNumeric + Gender + IsNonwhite, data=debate, Hess=TRUE)
summary(interact)
interactmargins2<- margins(interact)
summary(interactmargins2)
Editing to provide a sample of the data:
structure(list(Consent = c(1L, 1L, 1L, 1L, 1L, 1L), Gender = c(2L,
2L, 2L, 2L, 1L, 1L), IsFemale = c(0L, 0L, NA, 0L, NA, 1L), Age = c(19L,
19L, 19L, 19L, 19L, 20L), Race = c(1L, 1L, 4L, 1L, 4L, 1L), IsNonwhite = c(0L,
0L, 1L, 0L, 1L, 0L), PartyID = c(1L, 2L, 1L, 1L, 1L, 1L), StrongDem = c(1L,
NA, 1L, 1L, 2L, 2L), StrongRep = c(NA, 1L, NA, NA, NA, NA), IndCloser = c(NA_integer_,
NA_integer_, NA_integer_, NA_integer_, NA_integer_, NA_integer_
), DemImportant = c(1L, NA, 2L, 1L, 2L, 3L), DemDescribe = c(2L,
NA, 2L, 1L, 2L, 2L), DemWeThey = c(2L, NA, 2L, 2L, 3L, 4L), DemThink = c(1L,
NA, 2L, 1L, 2L, 1L), RepImportant = c(NA, 1L, NA, NA, NA, NA),
RepDescribe = c(NA, 1L, NA, NA, NA, NA), RepWeThey = c(NA,
2L, NA, NA, NA, NA), RepThink = c(NA, 1L, NA, NA, NA, NA),
FeelingThermTrump = c(0L, 100L, 0L, 0L, 0L, NA), FeelingThermBiden = c(64L,
NA, 100L, 95L, 50L, 100L), WatchLive = c(1L, 1L, 1L, 1L,
1L, 1L), WatchAfter = c(1L, 1L, 1L, 1L, 1L, 1L), WatchDebate = structure(c(2L,
2L, 2L, 2L, 2L, 2L), .Label = c("", "WatchAll", "WatchNone",
"WatchSome"), class = "factor"), FollowCoverage = c(1L, 1L,
1L, 1L, 2L, 1L), FairnessHonesty = c(4L, 2L, 5L, 4L, 5L,
4L), WhoUnfair = structure(c(5L, 4L, 6L, 5L, 9L, 5L), .Label = c("",
"1,2", "1,2,3", "1,3", "2", "2,3", "3", "3,4", "4"), class = "factor"),
WhoDishonest = structure(c(6L, 2L, 6L, 6L, 5L, 6L), .Label = c("",
"Biden", "Moderator", "More than one", "Not Sure", "Trump"
), class = "factor"), TrumpFairnessRater = c(0L, 9L, 1L,
2L, 5L, NA), BidenFairnessRater = c(7L, 2L, 9L, 7L, 5L, 10L
), WallaceFairnessRater = c(10L, 2L, 6L, 4L, 8L, 10L), TrumpHonestyRater = c(1L,
10L, 1L, 2L, 5L, NA), BidenHonestyRater = c(6L, 2L, 9L, 10L,
5L, 10L), WallaceHonestyRater = c(10L, 0L, 6L, 8L, 8L, 10L
), Voting1 = c(1L, 1L, 1L, 1L, 1L, 1L), WhoVote1 = c(2L,
1L, 2L, 2L, 2L, 2L), WhoVoteLean1 = c(NA_integer_, NA_integer_,
NA_integer_, NA_integer_, NA_integer_, NA_integer_), TrustGov = c(3L,
3L, 4L, 3L, 2L, 5L), Q4_First.Click = c(14.215, 460.794,
160.691, 0, 8.308, 0), Q4_Last.Click = c(356.559, 461.175,
407.781, 0, 104.224, 0), Q4_Page.Submit = c(390.864, 461.601,
414.195, 449.768, 415.194, 414.337), Q4_Click.Count = c(24L,
2L, 8L, 0L, 3L, 0L), BidenInterruptTrump = c(21L, 19L, 21L,
22L, 20L, 25L), TrumpInterruptBiden = c(19L, 21L, 19L, 19L,
19L, 19L), ModeratorInterruptTrump = c(24L, 20L, 22L, 20L,
19L, 25L), ModeratorInterruptBiden = c(24L, 24L, 20L, 21L,
21L, 21L), BidenAggressive = c(20L, 18L, 22L, 20L, 20L, 24L
), TrumpAggressive = c(18L, 19L, 18L, 18L, 18L, 18L), ModeratorAggressivetoTrump = c(20L,
19L, 20L, 19L, 19L, 19L), ModeratorAggressivetoBiden = c(22L,
23L, 20L, 21L, 20L, 21L), BidenLie = c(8L, 6L, 8L, 9L, 9L,
8L), TrumpLie = c(8L, 11L, 8L, 10L, 10L, 8L), BidenMischarTrump = c(12L,
12L, 14L, 10L, 12L, 15L), TrumpMischarBiden = c(9L, 12L,
9L, 10L, 11L, 9L), ModeratorFavorTrump = c(13L, 14L, 10L,
13L, 11L, 12L), ModeratorFavorBiden = c(11L, 8L, 11L, 9L,
11L, 10L), UnfairCountTrump = c(3L, 4L, 4L, 2L, 1L, 1L),
UnfairCountBiden = c(5L, 2L, 5L, 3L, 2L, 5L), WhoVote2 = c(2L,
1L, 2L, 2L, 2L, 2L), WhoVoteLean2 = c(NA_integer_, NA_integer_,
NA_integer_, NA_integer_, NA_integer_, NA_integer_), TrustGov.1 = c(3L,
3L, 4L, 3L, 3L, 3L), OfficialsCare = c(3L, 3L, 3L, 3L, 5L,
7L), LoseTouch = c(2L, 4L, 1L, 3L, 3L, 2L), OnlyCareVotes = c(2L,
4L, 1L, 4L, 2L, 1L)), row.names = c(NA, 6L), class = "data.frame")

full_join adding extra rows and NA in r

I have two data frames that I am trying to join using full_join, here is a subset of my data:
df1 <- structure(list(Team = structure(c(4L, 3L, 5L, 6L, 7L, 7L, 8L,
8L, 9L, 9L, 10L, 10L, 11L, 11L, 12L, 12L, 14L, 13L, 15L, 15L,
16L, 16L, 17L, 17L, 18L, 18L, 19L, 19L, 20L, 20L, 21L, 22L, 23L,
23L, 24L, 24L, 25L, 25L, 28L, 28L, 29L, 29L, 30L, 30L, 31L, 31L,
32L, 32L, 33L, 33L, 34L, 34L, 2L, 1L, 26L, 27L), .Label = c("76ers",
"76ers ", "Bucks", "Bucks ", "Bull ", "Bulls ", "Cavaliers ",
"Celtics ", "Clippers ", "Grizzlies ", "Hawks ", "Heat ", "Hornets",
"Hornets ", "Jazz ", "Kings ", "Knicks ", "Lakers ", "Magic ",
"Mavericks ", "Net ", "Nets ", "Nuggets ", "Pacers ", "Pelicans ",
"Pistons", "Pistons ", "Raptors ", "Rockets ", "Spurs ", "Thunder ",
"Timberwolves ", "Warriors ", "Wizards "), class = "factor"),
Injury.Count = c(3L, 3L, 1L, 1L, 1L, 2L, 0L, 2L, 1L, 1L,
0L, 2L, 1L, 0L, 5L, 4L, 3L, 2L, 3L, 0L, 3L, 3L, 4L, 6L, 5L,
0L, 2L, 2L, 1L, 2L, 0L, 1L, 3L, 4L, 2L, 6L, 2L, 1L, 1L, 1L,
3L, 3L, 4L, 5L, 1L, 6L, 4L, 2L, 0L, 2L, 2L, 1L, 5L, 6L, 1L,
1L), HomevsAway = structure(c(1L, 2L, 1L, 2L, 1L, 2L, 1L,
2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L,
1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L,
2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L,
1L, 2L, 1L, 2L), .Label = c("0", "1"), class = "factor")), row.names = c(NA,
-56L), class = "data.frame")
df2 <- structure(list(Team = structure(c(1L, 1L, 2L, 2L, 3L, 4L, 4L,
5L, 6L, 7L, 8L, 9L, 9L, 10L, 10L, 11L, 12L, 12L, 13L, 13L, 14L,
15L, 15L, 16L, 16L, 17L, 18L, 18L, 19L, 19L, 20L, 20L, 21L, 21L,
22L, 22L, 23L, 23L, 24L, 24L, 25L, 25L, 26L, 26L, 27L, 28L, 28L,
3L, 5L, 6L, 7L, 8L, 11L, 14L, 17L, 27L), .Label = c("76ers",
"Bucks", "Bulls", "Cavaliers", "Celtics", "Clippers", "Grizzlies",
"Hawks", "Heat", "Hornets", "Jazz", "Kings", "Knicks", "Lakers",
"Magic", "Mavericks", "Nets", "Nuggets", "Pacers", "Pelicans",
"Pistons", "Raptors", "Rockets", "Spurs", "Thunder", "Timberwolves",
"Warriors", "Wizards"), class = "factor"), HomevsAway = structure(c(1L,
2L, 1L, 2L, 1L, 1L, 2L, 2L, 2L, 2L, 1L, 1L, 2L, 1L, 2L, 1L, 1L,
2L, 1L, 2L, 1L, 1L, 2L, 1L, 2L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L,
2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 1L, 2L, 2L, 1L, 2L, 2L, 1L,
1L, 1L, 2L, 2L, 2L, 1L, 1L), .Label = c("0", "1"), class = "factor"),
t_1 = c(55.883, 140.1, 32.2, 37.967, 29.85, 24.317, 57.316,
17.967, 19.05, 36.95, 16.167, 95.317, 86.533, 21.334, 52.567,
40.75, 28.3, 68.15, 97.067, 102.233, 26.866, 71.033, 34.467,
24.233, 42.033, 22.433, 59.033, 41.516, 12.7, 107.996, 6.5,
32.783, 0, 23.217, 13.93, 0, 54.88, 23.617, 83.834, 106.794,
17.56, 27.76, 85.83, 0.017, 35.183, 22.467, 25.033, 0, 0,
0, 0, 0, 0, 0, 0, 0), t_3 = c(197.3164, 388.6827, 126.2663,
111.916, 61.95, 91.55, 167.067, 104.083, 71.067, 135.383,
45.633, 261.317, 267.399, 114.6997, 159.2, 152.034, 84.8337,
204.3003, 351.449, 376.317, 86.333, 213.9, 99.767, 65.1,
131.767, 73.317, 126.416, 129.066, 73.383, 347.0994, 4761,
113.367, 0, 89.933, 59.8, 0, 188.983, 124.384, 215.666, 289.9667,
92, 144.2497, 254.083, 32.0333, 122.1837, 102.533, 82.817,
0, 0, 0, 0, 0, 0, 0, 0, 0)), row.names = c(NA, -56L), groups = structure(list(
Team = structure(1:28, .Label = c("76ers", "Bucks", "Bulls",
"Cavaliers", "Celtics", "Clippers", "Grizzlies", "Hawks",
"Heat", "Hornets", "Jazz", "Kings", "Knicks", "Lakers", "Magic",
"Mavericks", "Nets", "Nuggets", "Pacers", "Pelicans", "Pistons",
"Raptors", "Rockets", "Spurs", "Thunder", "Timberwolves",
"Warriors", "Wizards"), class = "factor"), .rows = structure(list(
1:2, 3:4, c(5L, 48L), 6:7, c(8L, 49L), c(9L, 50L), c(10L,
51L), c(11L, 52L), 12:13, 14:15, c(16L, 53L), 17:18,
19:20, c(21L, 54L), 22:23, 24:25, c(26L, 55L), 27:28,
29:30, 31:32, 33:34, 35:36, 37:38, 39:40, 41:42, 43:44,
c(45L, 56L), 46:47), ptype = integer(0), class = c("vctrs_list_of",
"vctrs_vctr", "list"))), row.names = c(NA, 28L), class = c("tbl_df",
"tbl", "data.frame"), .drop = TRUE), class = c("grouped_df",
"tbl_df", "tbl", "data.frame"))
I have tried to join the data using full_join:
LR <- full_join(df1, df2, by = c("HomevsAway", "Team"))
The output of LR I am receiving is giving me extra rows with random NA's involved. My expected output should be a 56rowx5col table.
The problem is that in your first data.frame the Team names have a trailing space. This means that instead of the string "Bucks" you have the string "Bucks ".
These two strings cannot be joined.
Here is how you can fix your data. First delete leading spaces using sub and then transform the Team into a character vector. Then the full_join works as planned:
df1_new <- df1 %>% as_tibble() %>%
mutate(Team = sub(" +", "", as.character(Team)))
df2_new <- df2 %>%
mutate(Team = as.character(Team))
df1_new %>% full_join(df2_new, by = c("Team", "HomevsAway"))
# A tibble: 58 x 5
Team Injury.Count HomevsAway t_1 t_3
<chr> <int> <fct> <dbl> <dbl>
1 Bucks 3 0 32.2 126.
2 Bucks 3 1 38.0 112.
3 Bull 1 0 NA NA
4 Bulls 1 1 0 0
5 Cavaliers 1 0 24.3 91.6
6 Cavaliers 2 1 57.3 167.
7 Celtics 0 0 0 0
8 Celtics 2 1 18.0 104.
9 Clippers 1 0 0 0
10 Clippers 1 1 19.0 71.1
Note that there are still a few NAs. This is due to some typos: Bull vs Bulls and Net vs Nets.

How to create a faceted boxplot with the significant differences, and 2 measured variables?

I managed to create a faceted boxplot with my 2 quantitative variables;
I know how to run a kruskal-wallis followed by a Wilcoxon test and show the significant differences with letters in the boxplot but only in a simple boxplot, with one variable and without facet. How can I do ?
(If possible, I would like to put the siginificant differences with letters, I wish I would be able to post the pictures of what I already done but apparently I'm not allowed)
Also, I have another question; Which test does the function stat_function_mean execute ? I tried to use this function, but I don't know how to use it... Here is my code without the test, only the facetted boxplot with my two variables :
Code for my facet boxplot with 2 measured variables ( FF and FM)
dat.m2 <- melt(pheno,id.vars=c("fusion","Genotype","Hormone"),
measure.vars=c('FF','MF'))
dat.m2$fusion<-factor(dat.m2$fusion, levels=c("Control", "CK 20 mg/L", "CK 100 mg/L", "CK 500 mg/L", "GA 20 mg/L", "GA 100 mg/L", "GA 500 mg/L"))
levels(dat.m2$fusion)
ggplot(dat.m2) +
geom_boxplot(aes(x=fusion, y=value, colour=variable))+
facet_wrap(~Genotype)+
xlab(" ")+
ylab("Days after sowing")
Code to add significant differences on the graph, with letters, but with only 1 measured variable (FF), without facet
mymat <-tri.to.squ(pp$p.value)
mymat
myletters <- multcompLetters(mymat,compare="<=",threshold=0.05,Letters=letters)
myletters
myletters_df <- data.frame(fusion=names(myletters$Letters),letter = myletters$Letters )
myletters_df
ggplot(pheno, aes(x=fusion, y=FF, colour=fusion))+
geom_boxplot()+
geom_text(data = myletters_df, aes(label = letter, y = 30 ), colour="black", size=5)+
ylab("Days after sowing")+
xlab("")+
labs(title="Days to female flower production")+
theme(plot.title = element_text(hjust = 0.5))+
> dput(pheno)
structure(list(Genotype = structure(c(2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L,
4L, 4L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 3L, 3L,
3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L,
4L, 4L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 3L, 3L,
3L, 3L, 3L, 3L, 4L, 4L, 4L, 4L, 4L, 4L), .Label = c("F1045",
"FF", "M1585", "M1610"), class = "factor"), X = structure(c(1L,
105L, 116L, 127L, 138L, 149L, 160L, 171L, 182L, 2L, 13L, 24L,
35L, 46L, 57L, 68L, 79L, 90L, 101L, 106L, 107L, 108L, 109L, 110L,
111L, 112L, 113L, 114L, 115L, 117L, 118L, 119L, 120L, 121L, 122L,
123L, 124L, 125L, 126L, 128L, 129L, 130L, 131L, 132L, 133L, 134L,
135L, 136L, 137L, 139L, 140L, 141L, 142L, 143L, 144L, 145L, 146L,
147L, 148L, 150L, 151L, 152L, 153L, 154L, 155L, 156L, 157L, 158L,
159L, 161L, 162L, 163L, 164L, 165L, 166L, 167L, 168L, 169L, 170L,
172L, 173L, 174L, 175L, 176L, 177L, 178L, 179L, 180L, 181L, 183L,
184L, 185L, 186L, 187L, 188L, 189L, 190L, 191L, 192L, 3L, 4L,
5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 14L, 15L, 16L, 17L, 18L, 19L,
20L, 21L, 22L, 23L, 25L, 26L, 27L, 28L, 29L, 30L, 31L, 32L, 33L,
34L, 36L, 37L, 38L, 39L, 40L, 41L, 42L, 43L, 44L, 45L, 47L, 48L,
49L, 50L, 51L, 52L, 53L, 54L, 55L, 56L, 58L, 59L, 60L, 61L, 62L,
63L, 64L, 65L, 66L, 67L, 69L, 70L, 71L, 72L, 73L, 74L, 75L, 76L,
77L, 78L, 80L, 81L, 82L, 83L, 84L, 85L, 86L, 87L, 88L, 89L, 91L,
92L, 93L, 94L, 95L, 96L, 97L, 98L, 99L, 100L, 102L, 103L, 104L
), .Label = c("H1", "H10", "H100", "H101", "H102", "H103", "H104",
"H105", "H106", "H107", "H108", "H109", "H11", "H110", "H111",
"H112", "H113", "H114", "H115", "H116", "H117", "H118", "H119",
"H12", "H120", "H121", "H122", "H123", "H124", "H125", "H126",
"H127", "H128", "H129", "H13", "H130", "H131", "H132", "H133",
"H134", "H135", "H136", "H137", "H138", "H139", "H14", "H140",
"H141", "H142", "H143", "H144", "H145", "H146", "H147", "H148",
"H149", "H15", "H150", "H151", "H152", "H153", "H154", "H155",
"H156", "H157", "H158", "H159", "H16", "H160", "H161", "H162",
"H163", "H164", "H165", "H166", "H167", "H168", "H169", "H17",
"H170", "H171", "H172", "H173", "H174", "H175", "H176", "H177",
"H178", "H179", "H18", "H180", "H181", "H182", "H183", "H184",
"H185", "H186", "H187", "H188", "H189", "H19", "H190", "H191",
"H192", "H2", "H20", "H21", "H22", "H23", "H24", "H25", "H26",
"H27", "H28", "H29", "H3", "H30", "H31", "H32", "H33", "H34",
"H35", "H36", "H37", "H38", "H39", "H4", "H40", "H41", "H42",
"H43", "H44", "H45", "H46", "H47", "H48", "H49", "H5", "H50",
"H51", "H52", "H53", "H54", "H55", "H56", "H57", "H58", "H59",
"H6", "H60", "H61", "H62", "H63", "H64", "H65", "H66", "H67",
"H68", "H69", "H7", "H70", "H71", "H72", "H73", "H74", "H75",
"H76", "H77", "H78", "H79", "H8", "H80", "H81", "H82", "H83",
"H84", "H85", "H86", "H87", "H88", "H89", "H9", "H90", "H91",
"H92", "H93", "H94", "H95", "H96", "H97", "H98", "H99"), class = "factor"),
Hormone = structure(c(2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 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, 1L, 4L, 4L, 4L, 8L, 20L, 4L, 20L, 12L, 4L,
14L, 14L, 11L, 11L, 15L, 15L, 11L, 11L, 9L, 15L, 9L, 9L,
11L, 11L, 14L, 1L, 5L, 4L, 4L, 20L, 20L, 20L, 20L, 20L, 20L,
20L, 20L, 20L, 15L, 15L, 14L, 13L, 15L, 15L, 11L, 9L, 9L,
11L, 9L, 11L, 1L, 20L, 1L, 20L, 20L, 20L, 20L, 1L, 1L, 4L,
20L, 20L, 20L, 15L, 15L, 14L, 15L, 1L, 15L, 15L, 20L, 11L,
11L, 11L, 11L, 15L, 10L, 10L, 16L, 10L, 12L, 10L, 17L, 8L,
16L, 12L, 8L, 4L, 4L, 8L, 20L, 10L, 1L, 20L, NA, 12L, 10L,
20L, 20L, 20L, 1L, 20L, 1L, 20L, 12L, 16L, 12L, 2L, 8L, 4L,
10L, 4L, 4L, 4L, 10L, 8L, 4L, 8L, 20L, 20L, 20L, NA, 20L,
1L, 20L, 1L, 8L, 20L, 1L, 1L, 7L, 17L, 19L, 19L, 12L, 10L,
12L, 19L, 10L, 10L, 10L, 17L), .Label = c("10-mei", "13-jun",
"14-apr", "14-mei", "17-mei", "18-jun", "21-jun", "21-mei",
"23-apr", "24-mei", "26-apr", "28-mei", "3-apr", "3-mei",
"30-apr", "31-mei", "4-jun", "5-jul", "7-jun", "7-mei"), class = "factor"),
FH = c(3.5, 6, 9, 16, 5.5, 12, 11.5, 4, 4.5, 6, 8, 5, 4.5,
3.5, 4, 5, 20, 42, 14, 40, 27, 42, 27, 26, 16, 18, 35, 17,
20, 28, 15, 20, 33, 32, 14.5, 14.5, 14.5, 35, 32, 12.5, 13.5,
12, 14.5, 12, 15, 14.5, 18, 18, 18.5, 35, 23, 25, 30, 37,
53, 27.5, 37, 25.5, 35, 47, 8.5, 20.5, 13, 14.5, 13.5, 18.5,
10.5, 10, 14.3, 18.5, 15.3, 11.7, 16, 15, 13.5, 26, 36, 30,
43, 23.5, 23.5, 31.5, 29, 30.5, 30, 29, 30, 24.5, 19, 23,
21.5, 26.5, 18.5, 20, 15, 12.3, 17, 12, 15, 13, 43614, 25,
27, 22.5, 35, 23.5, 30, 42, 42, 55, 32.5, 26, 26, 9.5, 4.5,
5.5, 5, 15.5, 10, 4.5, 8.5, 6, 5, 5.5, 5, 4.5, 30, 20, 16,
16, 20, 22, 30, 22, 25, 11, 13.5, 11, 11, 14, 6, NA, 5.5,
7, NA, 12, 14, 7, 9.5, 6.5, 9, 8.5, 12.5, 8, 27, 33, 35,
32, 17, 14, 22, 11, 17, 12, 25, 22, 15, 10, 5, 3, 4, NA,
5, 8, 4.5, 6, 7, 5, 5.5, 7, 42, 23, 23, 21, 14, 21, 17, 22,
19, 18, 17, 17), SRDT = structure(c(2L, 7L, 14L, NA, 7L,
8L, 7L, NA, NA, NA, 3L, NA, 18L, 15L, 17L, 17L, 18L, 18L,
NA, 18L, 15L, 17L, 15L, 20L, 2L, NA, 11L, 17L, 18L, 2L, 2L,
2L, 14L, 12L, 17L, 15L, 12L, 9L, 9L, 6L, 6L, 15L, 15L, 15L,
15L, NA, 17L, 15L, 10L, 11L, 11L, 10L, 11L, 17L, 5L, 21L,
6L, NA, 20L, 5L, 12L, 7L, NA, 17L, 17L, 15L, 15L, 10L, 10L,
6L, 10L, 10L, 21L, NA, 15L, 15L, 5L, 15L, 15L, 11L, 10L,
21L, 1L, 21L, 21L, 21L, 1L, 5L, 18L, 2L, 9L, 9L, NA, 12L,
10L, NA, 16L, 6L, 6L, 15L, 6L, 10L, 10L, 10L, 1L, 10L, 1L,
21L, 21L, 1L, 21L, 5L, 18L, 2L, 17L, 20L, 9L, 14L, 5L, 9L,
9L, 11L, NA, 18L, 10L, 18L, 20L, 4L, 9L, 7L, 2L, 2L, 7L,
5L, 17L, 17L, 11L, 10L, 12L, 2L, 14L, 19L, 19L, 19L, NA,
NA, 2L, 11L, 17L, 14L, 17L, 9L, 10L, 10L, 2L, 7L, 17L, 14L,
2L, 11L, 20L, 2L, 15L, 15L, 11L, 5L, NA, 10L, NA, 2L, 8L,
NA, NA, 14L, 5L, 15L, 15L, NA, 22L, NA, 9L, 9L, 19L, 9L,
9L, 22L, 20L, 13L, 7L, 20L, 15L, 20L), .Label = c("10-mei",
"11-jun", "13-jun", "13-mei", "14-mei", "17-mei", "18-jun",
"2-jul", "21-jun", "21-mei", "24-mei", "25-jun", "26-jun",
"28-jun", "28-mei", "3-mei", "31-mei", "4-jun", "5-jul",
"7-jun", "7-mei", "9-jul"), class = "factor"), MH = c(26,
50, 58, NA, 46, 58, 61, NA, NA, NA, 40, NA, 68, 48, 47, 42,
26, 50, NA, 48, 27, 42, 27, 48, 25, NA, 25, 17, 20, 18, 32,
19, 75, 75, 65, 70, 73, 73, 71, 65, 70, 60, 80, 70, 70, NA,
54, 45, 45, 45, 45, 40, 49, 53, 45, 27.5, 44, NA, NA, 47,
47, 62, NA, 75, 60, 75, 70, 65, 80, 67, 80, 75, 52, NA, 67,
68, 26, 55, 60, 60, 60, 31.5, 39, 30.5, 30, 29, 39, 39, 86,
74, 80, 76, NA, 69, 80, NA, 44, 70, 70, 65, 43, 60, 57, 57,
45, 60, 39, 35, 32.5, 27, 32.5, 43, 70, 75, 60, 66, 58, 48,
41, NA, 44, 42, NA, 44, 39, 40, 48, 53, 50, 50, 45, 45, 50,
13, 25, 11, 21, 20.5, 46, 44, 54, 25, 20, 25, NA, NA, 28,
33, 36, 40, 21, 36, 23.5, 21, 44, 60, 37, 37, 55, 24, 45,
45, 35, 30, 25, 12, 27, 10, NA, 53, 35, NA, NA, 43, 11, 13,
7, NA, 22, NA, 42, 46, NA, 41, 43, 40, 26, 45, 35, 29, 17,
22), SEEDT = structure(c(2L, 4L, 9L, NA, 4L, 5L, 4L, NA,
NA, NA, 4L, NA, 12L, 11L, 11L, 11L, 4L, 3L, NA, 4L, 15L,
4L, 8L, 5L, 7L, NA, 2L, 2L, 8L, 13L, 8L, NA, 13L, 8L, 15L,
15L, 8L, 7L, 7L, 10L, 10L, 11L, 6L, 10L, 10L, NA, 3L, 11L,
12L, 12L, 12L, 12L, 4L, 4L, 12L, 12L, 12L, NA, 9L, 12L, NA,
4L, NA, 2L, 15L, 2L, 15L, 14L, 10L, 12L, 12L, 11L, 11L, NA,
2L, 12L, 8L, 3L, 15L, 11L, 11L, 10L, 10L, 10L, 10L, 10L,
10L, 10L, 2L, 2L, 7L, 7L, NA, 8L, 10L, NA, 10L, 10L, 10L,
15L, 10L, 12L, 12L, 10L, 11L, 11L, 10L, 10L, 10L, 11L, 10L,
11L, 12L, 2L, 12L, 4L, 7L, 9L, 10L, 7L, 7L, 10L, NA, 12L,
10L, 15L, 2L, 4L, 8L, 8L, 4L, 4L, 13L, 12L, NA, NA, 4L, 7L,
NA, 7L, 13L, 13L, 13L, NA, NA, NA, 2L, 2L, NA, NA, NA, 8L,
NA, NA, 4L, 4L, 2L, NA, 4L, 2L, 7L, 7L, 7L, 2L, 2L, 15L,
1L, 15L, NA, 2L, 5L, NA, NA, 5L, 13L, NA, NA, NA, NA, NA,
16L, 16L, 13L, 16L, 7L, 1L, 7L, 16L, 7L, 7L, 7L, NA), .Label = c("11-jul",
"11-jun", "13-jun", "18-jun", "2-jul", "20-mei", "21-jun",
"25-jun", "28-jun", "28-mei", "31-mei", "4-jun", "5-jul",
"6-apr", "7-jun", "9-jul"), class = "factor"), FERMK = c(7L,
8L, 8L, 7L, 8L, 8L, 8L, 4L, NA, NA, 5L, 7L, 7L, 6L, 7L, 6L,
4L, 6L, NA, 4L, 3L, 4L, 4L, 4L, 2L, NA, 2L, 2L, 2L, 1L, 2L,
2L, 8L, 6L, 6L, 6L, 7L, 7L, 7L, 6L, 6L, 7L, 7L, 6L, 4L, 6L,
6L, 5L, 6L, 5L, 5L, 6L, 5L, 4L, 2L, 5L, NA, NA, 4L, 2L, 5L,
5L, NA, 7L, 7L, 8L, 6L, 6L, 7L, NA, 7L, 7L, 6L, 5L, 5L, 5L,
4L, 4L, 6L, 7L, 6L, 4L, 2L, 2L, 2L, 2L, 2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 2L, 2L, 2L, 2L, 3L, 2L, 2L, 5L, 5L, 4L,
1L, 4L, NA, 2L, 1L, NA, NA, 2L, 2L, 0L, 0L, NA, 1L, NA, 4L,
2L, 1L, 2L, 1L, 2L, 4L, 1L, 2L, 4L, 3L, NA), FF = c(39L,
43L, 50L, 60L, 43L, 20L, 46L, 39L, 29L, 32L, 43L, 32L, 29L,
29L, 29L, 32L, 64L, 64L, 85L, 64L, 64L, 67L, 64L, 64L, 71L,
71L, 64L, 67L, 71L, 102L, 64L, 85L, 43L, 43L, 36L, 36L, 36L,
43L, 43L, 32L, 32L, 32L, 29L, 29L, 29L, 29L, 43L, 43L, 43L,
50L, 46L, 50L, 50L, 50L, 57L, 43L, 50L, 43L, 64L, 50L, 39L,
39L, 32L, 32L, 36L, 36L, 32L, 32L, 29L, 36L, 29L, 29L, 32L,
32L, 39L, 46L, 53L, 50L, 50L, 43L, 43L, 43L, 43L, 43L, 43L,
43L, 43L, 43L, 36L, 36L, 39L, 9L, 36L, 36L, 32L, 29L, 29L,
32L, 29L, 32L, 46L, 43L, 46L, 43L, 43L, 43L, 43L, 46L, 46L,
50L, 43L, 43L, 43L, 36L, 36L, 39L, 36L, 46L, 36L, 36L, 43L,
32L, 32L, 32L, 32L, 36L, 60L, 60L, 67L, 60L, 64L, 60L, 71L,
57L, 67L, 64L, 57L, 50L, 50L, 57L, 43L, 60L, 46L, 43L, NA,
64L, 60L, 43L, 43L, 43L, 46L, 43L, 46L, 43L, 64L, 67L, 64L,
80L, 57L, 50L, 60L, 50L, 50L, 50L, 60L, 57L, 50L, 57L, 43L,
43L, 43L, NA, 43L, 46L, 43L, 46L, 57L, 43L, 46L, 46L, 88L,
71L, 74L, 74L, 64L, 60L, 64L, 74L, 60L, 60L, 60L, 71L), MF = c(78L,
85L, 95L, NA, 85L, 99L, 85L, NA, NA, NA, 80L, NA, 71L, 64L,
67L, 67L, 71L, 71L, NA, 71L, 64L, 67L, 64L, 74L, 78L, NA,
60L, 67L, 71L, 78L, 78L, 78L, 95L, 92L, 67L, 64L, 92L, 88L,
88L, 53L, 53L, 64L, 64L, 64L, 64L, NA, 67L, 64L, 57L, 60L,
60L, 57L, 60L, 67L, 50L, 43L, 53L, NA, 74L, 50L, 92L, 85L,
NA, 67L, 67L, 64L, 64L, 57L, 57L, 53L, 57L, 57L, 43L, NA,
64L, 64L, 50L, 64L, 64L, 60L, 57L, 43L, 46L, 43L, 43L, 43L,
46L, 50L, 71L, 78L, 88L, 88L, NA, 92L, 57L, NA, 39L, 53L,
53L, 64L, 53L, 57L, 57L, 57L, 46L, 57L, 46L, 43L, 43L, 46L,
43L, 50L, 71L, 78L, 67L, 74L, 88L, 95L, 50L, 88L, 88L, 60L,
NA, 71L, 57L, 71L, 74L, 49L, 88L, 85L, 78L, 78L, 85L, 50L,
67L, 67L, 60L, 57L, 92L, 78L, 95L, 102L, 102L, 102L, NA,
NA, 78L, 60L, 67L, 95L, 67L, 88L, 57L, 57L, 78L, 85L, 67L,
95L, 78L, 60L, 74L, 78L, 64L, 64L, 60L, 50L, NA, 57L, NA,
78L, 99L, NA, NA, 95L, 50L, 64L, 64L, NA, 106L, NA, 88L,
88L, 102L, 88L, 88L, 106L, 74L, 93L, 85L, 74L, 64L, 74L),
speed = c(0.08974359, 0.139534884, 0.18, 0.266666667, 0.127906977,
0.6, 0.25, 0.102564103, 0.155172414, 0.1875, 0.186046512,
0.15625, 0.155172414, 0.120689655, 0.137931034, 0.15625,
0.3125, 0.65625, 0.164705882, 0.625, 0.421875, 0.626865672,
0.421875, 0.40625, 0.225352113, 0.253521127, 0.546875, 0.253731343,
0.281690141, 0.274509804, 0.234375, 0.235294118, 0.76744186,
0.744186047, 0.402777778, 0.402777778, 0.402777778, 0.813953488,
0.744186047, 0.390625, 0.421875, 0.375, 0.5, 0.413793103,
0.517241379, 0.5, 0.418604651, 0.418604651, 0.430232558,
0.7, 0.5, 0.5, 0.6, 0.74, 0.929824561, 0.639534884, 0.74,
0.593023256, 0.546875, 0.94, 0.217948718, 0.525641026, 0.40625,
0.453125, 0.375, 0.513888889, 0.328125, 0.3125, 0.493103448,
0.513888889, 0.527586207, 0.403448276, 0.5, 0.46875, 0.346153846,
0.565217391, 0.679245283, 0.6, 0.86, 0.546511628, 0.546511628,
0.73255814, 0.674418605, 0.709302326, 0.697674419, 0.674418605,
0.697674419, 0.569767442, 0.527777778, 0.638888889, 0.551282051,
2.944444444, 0.513888889, 0.555555556, 0.46875, 0.424137931,
0.586206897, 0.375, 0.517241379, 0.40625, 948.1304348, 0.581395349,
0.586956522, 0.523255814, 0.813953488, 0.546511628, 0.697674419,
0.913043478, 0.913043478, 1.1, 0.755813953, 0.604651163,
0.604651163, 0.263888889, 0.125, 0.141025641, 0.138888889,
0.336956522, 0.277777778, 0.125, 0.197674419, 0.1875, 0.15625,
0.171875, 0.15625, 0.125, 0.5, 0.333333333, 0.23880597, 0.266666667,
0.3125, 0.366666667, 0.422535211, 0.385964912, 0.373134328,
0.171875, 0.236842105, 0.22, 0.22, 0.245614035, 0.139534884,
NA, 0.119565217, 0.162790698, NA, 0.1875, 0.233333333, 0.162790698,
0.220930233, 0.151162791, 0.195652174, 0.197674419, 0.27173913,
0.186046512, 0.421875, 0.492537313, 0.546875, 0.4, 0.298245614,
0.28, 0.366666667, 0.22, 0.34, 0.24, 0.416666667, 0.385964912,
0.3, 0.175438596, 0.11627907, 0.069767442, 0.093023256, NA,
0.11627907, 0.173913043, 0.104651163, 0.130434783, 0.122807018,
0.11627907, 0.119565217, 0.152173913, 0.477272727, 0.323943662,
0.310810811, 0.283783784, 0.21875, 0.35, 0.265625, 0.297297297,
0.316666667, 0.3, 0.283333333, 0.23943662), ratiofm = c(7,
4, 8, 7, 8, 8, 8, NA, NA, NA, 5, 3.5, NA, NA, NA, NA, 4,
6, NA, 4, 3, 2, 4, 4, 0.5, NA, 0.4, 0.4, 0.5, 0.2, 0.666666667,
0.5, 8, 6, 6, 6, 7, 7, 7, 3, 3, 3.5, 3.5, 6, 4, NA, 3, 2.5,
3, 5, 2.5, 3, 5, 4, 0.5, 1, NA, NA, 0.8, 0.333333333, 5,
5, NA, 7, 7, NA, 6, 6, 7, NA, 3.5, 7, 3, NA, 2.5, NA, 1,
1.333333333, 3, 3.5, 6, 1, 0.4, 0.4, 0.5, 0.4, 0.285714286,
0.333333333, 8, 7, 7, 7, NA, 7, 3.5, NA, 7, 7, 7, 7, 1.666666667,
1.666666667, 4, 1.25, 1.2, 2, 1.5, 0.285714286, 0.4, 0.25,
1, 2, NA, 6, 8, 7, 0.857142857, 6, NA, 7, 7, NA, NA, NA,
NA, NA, 3.5, 1.666666667, 5, 4, 2, 4, 2, 0.333333333, 0.333333333,
NA, 0.75, 0.5, NA, 1.5, 3, 5, 5, 6, NA, 6, 4, 2, 5, 5, 5,
5, NA, NA, 4, 4, 3, 2.5, 3, 2.5, 2.333333333, 3.5, 3.5, 0.6,
0.4, 0.75, 3, 1, NA, 2.5, 5, NA, NA, 2.5, 1.5, NA, NA, NA,
4, NA, 1.25, 2, 5, 2.5, 6, 2, 1, 3, 1.5, 1, 1.666666667,
NA)), class = "data.frame", row.names = c(NA, -192L))
It would be more clear with pictures of my graphs, but apparently I'm not allowed yet to include pictures in my posts, sorry
Thanks in advance for your help
you can try
library(tidyverse)
df %>%
as_tibble() %>%
ggplot(aes(x=fusion, y=FF)) +
geom_boxplot(aes(colour=fusion))+
ggsignif::geom_signif(comparisons = combn(levels(df$fusion), 2, simplify = F), step_increase = 0.3) +
ggpubr::stat_compare_means() +
facet_wrap(~Genotype)+
xlab(" ")+
ylab("Days after sowing")

How to re order datas in ggplot2

I'm trying to re order my datas, I already found the code to use but it doesn't seem to work...
Can you help me please ?
This is my code :
#code for my boxplot
dat.m2 <- melt(H1,id.vars='fusion', measure.vars=c('FF','FM'))
dat.m2 <- melt(H1,id.vars='fusion', measure.vars=c('FF','FM'))
ggplot(dat.m2)+ geom_boxplot(aes(x=fusion, y=value, colour=variable))+ facet_wrap(~H1$Genotype)+
xlab(" ")+ ylab("Days after sowing")
#code tried to re order
levels(dat.m2$fusion)
dat.m2$fusion<-factor(dat.m2$fusion, levels=c("Control", "CK20", "CK100", "CK500", "GA20", "GA100", "GA500"))
I tried to run again the first code after re ordering but it didn't work...
You can also find attached the image of the boxplot that I'm trying to modify
Thanks
EDIT :
> dput(head(H1, 20))
structure(list(Genotype = structure(c(2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 3L, 3L, 3L, 3L), .Label = c("F1045",
"FF", "M1585", "M1610"), class = "factor"), X = structure(c(1L,
105L, 116L, 127L, 138L, 149L, 160L, 171L, 182L, 2L, 13L, 24L,
35L, 46L, 57L, 68L, 79L, 90L, 101L, 106L), .Label = c("H1", "H10",
"H100", "H101", "H102", "H103", "H104", "H105", "H106", "H107",
"H108", "H109", "H11", "H110", "H111", "H112", "H113", "H114",
"H115", "H116", "H117", "H118", "H119", "H12", "H120", "H121",
"H122", "H123", "H124", "H125", "H126", "H127", "H128", "H129",
"H13", "H130", "H131", "H132", "H133", "H134", "H135", "H136",
"H137", "H138", "H139", "H14", "H140", "H141", "H142", "H143",
"H144", "H145", "H146", "H147", "H148", "H149", "H15", "H150",
"H151", "H152", "H153", "H154", "H155", "H156", "H157", "H158",
"H159", "H16", "H160", "H161", "H162", "H163", "H164", "H165",
"H166", "H167", "H168", "H169", "H17", "H170", "H171", "H172",
"H173", "H174", "H175", "H176", "H177", "H178", "H179", "H18",
"H180", "H181", "H182", "H183", "H184", "H185", "H186", "H187",
"H188", "H189", "H19", "H190", "H191", "H192", "H2", "H20", "H21",
"H22", "H23", "H24", "H25", "H26", "H27", "H28", "H29", "H3",
"H30", "H31", "H32", "H33", "H34", "H35", "H36", "H37", "H38",
"H39", "H4", "H40", "H41", "H42", "H43", "H44", "H45", "H46",
"H47", "H48", "H49", "H5", "H50", "H51", "H52", "H53", "H54",
"H55", "H56", "H57", "H58", "H59", "H6", "H60", "H61", "H62",
"H63", "H64", "H65", "H66", "H67", "H68", "H69", "H7", "H70",
"H71", "H72", "H73", "H74", "H75", "H76", "H77", "H78", "H79",
"H8", "H80", "H81", "H82", "H83", "H84", "H85", "H86", "H87",
"H88", "H89", "H9", "H90", "H91", "H92", "H93", "H94", "H95",
"H96", "H97", "H98", "H99"), class = "factor"), Hormone = structure(c(2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L), .Label = c("CK", "Control", "GA"), class = "factor"),
Hormone.quantity = structure(c(4L, 4L, 4L, 4L, 4L, 4L, 4L,
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L), .Label = c("100",
"20", "500", "Control"), class = "factor"), fusion = structure(c(4L,
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L,
4L, 4L, 4L, 4L), .Label = c("CK 100", "CK 20", "CK 500",
"Control", "GA 100", "GA 20", "GA 500"), class = "factor"),
DL = c(16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L,
16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L, 16L), LI = c(100L,
100L, 100L, 100L, 100L, 100L, 100L, 100L, 100L, 100L, 100L,
100L, 100L, 100L, 100L, 100L, 100L, 100L, 100L, 100L), Temperature = c(21L,
21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L, 21L,
21L, 21L, 21L, 21L, 21L, 21L, 21L), Sowing.date = structure(c(1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L), .Label = "25-mrt", class = "factor"), BTD10 = structure(c(6L,
7L, 6L, 6L, 6L, 6L, 6L, 6L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L,
6L, 4L, 4L, 4L), .Label = c("16-apr", "17-apr", "18-apr",
"19-apr", "21-mei", "23-apr", "26-apr", "30-apr"), class = "factor"),
FFLDT = structure(c(13L, 18L, 4L, 9L, 18L, 3L, 2L, 13L, 8L,
10L, 18L, 10L, 8L, 8L, 8L, 10L, 11L, 11L, 1L, 11L), .Label = c("",
"10-mei", "14-apr", "14-mei", "17-mei", "18-jun", "21-mei",
"23-apr", "24-mei", "26-apr", "28-mei", "3-apr", "3-mei",
"30-apr", "31-mei", "4-jun", "7-jun", "7-mei"), class = "factor"),
FH = structure(c(42L, 62L, 67L, 18L, 59L, 7L, 5L, 52L, 53L,
62L, 65L, 58L, 53L, 42L, 52L, 58L, 24L, 55L, 1L, 54L), .Label = c("",
"10", "10,5", "11", "11,5", "11,7", "12", "12,3", "12,5",
"13", "13,5", "14", "14,3", "14,5", "15", "15,3", "15,5",
"16", "16-jan", "17", "18", "18,5", "19", "20", "20,5", "21",
"21,5", "22", "22,5", "23", "23,5", "24,5", "25", "25,5",
"26", "26,5", "27", "27,5", "29", "29-mei", "3", "3,5", "30",
"30,5", "31,5", "32", "32,5", "33", "35", "36", "37", "4",
"4,5", "40", "42", "43", "47", "5", "5,5", "53", "55", "6",
"6,5", "7", "8", "8,5", "9", "9,5"), class = "factor"), SRDT = structure(c(3L,
8L, 1L, 1L, 8L, 1L, 8L, NA, NA, NA, 4L, NA, 15L, 12L, 14L,
14L, 15L, 15L, 1L, 15L), .Label = c("", "10-mei", "11-jun",
"13-jun", "13-mei", "14-mei", "17-mei", "18-jun", "21-jun",
"21-mei", "24-mei", "28-mei", "3-mei", "31-mei", "4-jun",
"7-jun", "7-mei"), class = "factor"), MH = c(26, 50, NA,
NA, 46, NA, 61, NA, NA, NA, 40, NA, 68, 48, 47, 42, 26, 50,
NA, 48), SEEDT = structure(c(2L, 4L, 1L, 1L, 4L, 1L, 4L,
NA, NA, NA, 4L, NA, 9L, 8L, 8L, 8L, 4L, 3L, 1L, 4L), .Label = c("",
"11-jun", "13-jun", "18-jun", "20-mei", "21-jun", "28-mei",
"31-mei", "4-jun", "6-apr", "7-jun"), class = "factor"),
FERMK = c(7L, 8L, NA, NA, 8L, NA, 8L, NA, NA, NA, 5L, NA,
7L, 6L, 7L, 6L, NA, NA, NA, 4L), PLRMK = c(1L, 2L, NA, NA,
1L, NA, 1L, NA, NA, NA, 1L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, NA,
1L), BT = structure(c(5L, 6L, 5L, 5L, 5L, 5L, 5L, 5L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 5L, 4L, 4L, 4L), .Label = c("",
"22", "23", "25", "29", "32", "bino"), class = "factor"),
FF = c(39L, 43L, 50L, 60L, 43L, 20L, 46L, 39L, 29L, 32L,
43L, 32L, 29L, 29L, 29L, 32L, 64L, 64L, NA, 64L), FM = c(78L,
85L, NA, NA, 85L, NA, 85L, NA, NA, NA, 80L, NA, 71L, 64L,
67L, 67L, 71L, 71L, NA, 71L), SEED = c(78L, 85L, NA, NA,
85L, NA, 85L, NA, NA, NA, 85L, NA, 71L, 67L, 67L, 67L, 85L,
80L, NA, 85L)), row.names = c(NA, 20L), class = "data.frame")

Reshape a large matrix with missing values and multiple vars of interest [duplicate]

This question already has answers here:
Convert data from long format to wide format with multiple measure columns
(6 answers)
Closed 4 years ago.
I need to reorganize a large dataset into a specific format for further analysis. Right now the data are in long format, with multiple records through time for each point. I need to reshape the data so that each point has a single record, but it will add many new columns of the time-specific data. I’ve looked at previous similar posts but I need to ultimately convert several of the current variables into columns, and I can’t find an example of such. Is there a way to accomplish this in a single reshape, or will I have to do several and then concatenate the new columns back together? Another wrinkle before I post the example is that not all points were sampled at each time-step, so I need those values to show up as NA. For example, (see data below) SitePoint A1 was not sampled at all in 2012, SitePoint A10 was not sampled during the first round in 2012, but K83 was sampled all nine times.
mydatain <- structure(list(SitePoint = structure(c(1L, 1L, 1L, 1L, 1L, 1L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 3L, 3L, 3L, 3L, 3L, 3L, 3L, 3L,
4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 4L, 5L, 5L, 5L, 5L, 5L, 5L, 5L,
5L, 5L, 6L, 6L), .Label = c("A1", "A10", "K145", "K83", "T15",
"T213"), class = "factor"), Year_Rotation = structure(c(1L, 2L,
3L, 4L, 5L, 6L, 1L, 2L, 3L, 4L, 5L, 6L, 8L, 9L, 1L, 2L, 4L, 5L,
6L, 7L, 8L, 9L, 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 1L, 2L, 3L,
4L, 5L, 6L, 7L, 8L, 9L, 1L, 7L), .Label = c("2010_1", "2010_2",
"2010_3", "2011_1", "2011_2", "2011_3", "2012_1", "2012_2", "2012_3"
), class = "factor"), MR_Fire = structure(c(5L, 6L, 6L, 2L, 9L,
9L, 5L, 6L, 6L, 2L, 9L, 9L, 7L, 8L, 16L, 17L, 21L, 22L, 23L,
25L, 3L, 4L, 10L, 11L, 12L, 13L, 14L, 15L, 18L, 19L, 20L, 1L,
2L, 2L, 5L, 6L, 6L, 11L, 11L, 12L, 7L, 24L), .Label = c("0",
"1", "10", "11", "12", "13", "14", "15", "2", "23", "24", "25",
"35", "36", "37", "39", "40", "47", "48", "49", "51", "52", "53",
"8", "9"), class = "factor"), fire_seas = structure(c(2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 1L, 1L, 1L, 1L,
1L, 3L, 3L, 3L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L, 2L,
2L, 2L, 2L, 2L, 2L, 2L, 1L, 3L), .Label = c("dry", "fire", "wet"
), class = "factor"), OptTSF = c(1L, 1L, 1L, 1L, 1L, 1L, 1L,
1L, 1L, 1L, 1L, 1L, 1L, 1L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 1L,
1L, 1L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 0L, 0L,
0L, 1L, 1L)), .Names = c("SitePoint", "Year_Rotation", "MR_Fire",
"fire_seas", "OptTSF"), row.names = c(31L, 32L, 33L, 34L, 35L,
36L, 67L, 68L, 69L, 70L, 71L, 72L, 73L, 74L, 10543L, 10544L,
10545L, 10546L, 10547L, 10548L, 10549L, 10550L, 14988L, 14989L,
14990L, 14991L, 14992L, 14993L, 14994L, 14995L, 14996L, 17370L,
17371L, 17372L, 17373L, 17374L, 17375L, 17376L, 17377L, 17378L,
19353L, 19354L), class = "data.frame")
Ultimately I need something like this:
myfinal <- structure(list(SitePoint = structure(1:6, .Label = c("A1", "A10",
"K145", "K83", "T15", "T213"), class = "factor"), MR_Fire_2010_1 = c(12L,
12L, 39L, 23L, 0L, 14L), MR_Fire_2010_2 = c(13L, 13L, 40L, 24L,
1L, NA), MR_Fire_2010_3 = c(13L, 13L, NA, 25L, 1L, NA), MR_Fire_2011_1 = c(1L,
1L, 51L, 35L, 12L, NA), MR_Fire_2011_2 = c(2L, 2L, 52L, 36L,
13L, NA), MR_Fire_2011_3 = c(2L, 2L, 53L, 37L, 13L, NA), MR_Fire_2012_1 = c(NA,
NA, 9L, 47L, 24L, 8L), MR_Fire_2012_2 = c(NA, 14L, 10L, 48L,
24L, NA), MR_Fire_2012_3 = c(NA, 15L, 11L, 49L, 25L, NA), season_2010_1 = structure(c(2L,
2L, 1L, 2L, 2L, 1L), .Label = c("dry", "fire"), class = "factor"),
season_2010_2 = structure(c(2L, 2L, 1L, 2L, 2L, NA), .Label = c("dry",
"fire"), class = "factor"), season_2010_3 = structure(c(1L,
1L, NA, 1L, 1L, NA), .Label = "fire", class = "factor"),
season_2011_1 = structure(c(2L, 2L, 1L, 2L, 2L, NA), .Label = c("dry",
"fire"), class = "factor"), season_2011_2 = structure(c(2L,
2L, 1L, 2L, 2L, NA), .Label = c("dry", "fire"), class = "factor"),
season_2011_3 = structure(c(2L, 2L, 1L, 2L, 2L, NA), .Label = c("dry",
"fire"), class = "factor"), season_2012_1 = structure(c(NA,
NA, 2L, 1L, 1L, 2L), .Label = c("fire", "wet"), class = "factor"),
season_2012_2 = structure(c(NA, 1L, 2L, 1L, 1L, NA), .Label = c("fire",
"wet"), class = "factor"), season_2012_3 = structure(c(NA,
1L, 2L, 1L, 1L, NA), .Label = c("fire", "wet"), class = "factor"),
OptTSF_2010_1 = c(1L, 1L, 0L, 1L, 1L, 1L), OptTSF_2010_2 = c(1L,
1L, 0L, 1L, 1L, NA), OptTSF_2010_3 = c(1L, 1L, NA, 1L, 1L,
NA), OptTSF_2011_1 = c(1L, 1L, 0L, 0L, 1L, NA), OptTSF_2011_2 = c(1L,
1L, 0L, 0L, 1L, NA), OptTSF_2011_3 = c(1L, 1L, 0L, 0L, 1L,
NA), OptTSF_2012_1 = c(NA, NA, 1L, 0L, 0L, 1L), OptTSF_2012_2 = c(NA,
1L, 1L, 0L, 0L, NA), OptTSF_2012_3 = c(NA, 1L, 1L, 0L, 0L,
NA)), .Names = c("SitePoint", "MR_Fire_2010_1", "MR_Fire_2010_2",
"MR_Fire_2010_3", "MR_Fire_2011_1", "MR_Fire_2011_2", "MR_Fire_2011_3",
"MR_Fire_2012_1", "MR_Fire_2012_2", "MR_Fire_2012_3", "season_2010_1",
"season_2010_2", "season_2010_3", "season_2011_1", "season_2011_2",
"season_2011_3", "season_2012_1", "season_2012_2", "season_2012_3",
"OptTSF_2010_1", "OptTSF_2010_2", "OptTSF_2010_3", "OptTSF_2011_1",
"OptTSF_2011_2", "OptTSF_2011_3", "OptTSF_2012_1", "OptTSF_2012_2",
"OptTSF_2012_3"), class = "data.frame", row.names = c(NA, -6L
))
The actual dataset is about 23656 records X 15 variables, so doing it by hand is likely to cause major headaches and potential for mistakes. Any help or suggestions are appreciated. If this has been answered elsewhere, apologies. I couldn’t find anything directly applicable; everything seemed to related to three columns and only one of those being extracted as new variables. Thanks.
SP
dcast from the devel version of data.table i.e., v1.9.5 can cast multiple columns simultaneously. It can be installed from here.
library(data.table) ## v1.9.5+
dcast(setDT(mydatain), SitePoint~Year_Rotation,
value.var=c('MR_Fire', 'fire_seas', 'OptTSF'))
You can use reshape to change the structure of your dataframe from long to wide using the following code:
reshape(mydatain,timevar="Year_Rotation",idvar="SitePoint",direction="wide")

Resources