R 如何防止按组自动排序并保留原始顺序 1.

R 如何防止按组自动排序并保留原始顺序 1.,r,list,dataframe,R,List,Dataframe,假设我下载了一个名为econ\u dmg.csv的数据集: fileUrl <- "https://raw.githubusercontent.com/MichaelSodeke/DataSets/main/econ_dmg.csv" download.file(fileUrl, destfile="econ_dmg.csv", method = "curl", mode="wb") df <- read

假设我下载了一个名为
econ\u dmg.csv的数据集:

fileUrl <- "https://raw.githubusercontent.com/MichaelSodeke/DataSets/main/econ_dmg.csv"
download.file(fileUrl, destfile="econ_dmg.csv", method = "curl", mode="wb")
df <- read_csv("econ_dmg.csv") 
2. 然后,我将元素分组如下:

df2 <- df %>% group_by(state, max.net.loss)
3:问题 接下来,我将数据帧转换为具有以下内容的列表:

df3 <- group_split(df2)

请帮我修理。非常感谢

如果您想保留排序,可以将
状态
列转换为
因子
,默认情况下,它们在数据中显示时按字母顺序排序

library(dplyr)
df$state <- factor(df$state, levels = unique(df$state))
df2 <- group_split(df)
库(dplyr)

df$state您是否可以只添加和索引与原始索引匹配的列,然后在索引列上进行排序?您如何确定团队的订单?是第一次出现吗?
df3 <- group_split(df2)
> df3
<list_of<
  tbl_df<
    state       : factor<00fd4>
    evtype      : factor<70f44>
    max.net.loss: double
  >
>[72]>
[[1]]
# A tibble: 1 x 3
  state evtype        max.net.loss
  <fct> <fct>                <dbl>
1 AK    COASTAL FLOOD         1000

[[2]]
# A tibble: 1 x 3
  state evtype  max.net.loss
  <fct> <fct>          <dbl>
1 AL    TORNADO          960

[[3]]
# A tibble: 1 x 3
  state evtype     max.net.loss
  <fct> <fct>             <dbl>
1 AM    WATERSPOUT         5000

[[4]]
# A tibble: 1 x 3
  state evtype                   max.net.loss
  <fct> <fct>                           <dbl>
1 AN    MARINE THUNDERSTORM WIND          100

[[5]]
# A tibble: 1 x 3
  state evtype  max.net.loss
  <fct> <fct>          <dbl>
1 AR    TORNADO          950

[[6]]
# A tibble: 2 x 3
  state evtype         max.net.loss
  <fct> <fct>                 <dbl>
1 AS    HURRICANE               500
2 AS    TROPICAL STORM          500

[[7]]
# A tibble: 1 x 3
  state evtype max.net.loss
  <fct> <fct>         <dbl>
1 AZ    HAIL            900

[[8]]
# A tibble: 1 x 3
  state evtype    max.net.loss
  <fct> <fct>            <dbl>
1 CA    LANDSLIDE         1584

[[9]]
# A tibble: 1 x 3
  state evtype    max.net.loss
  <fct> <fct>            <dbl>
1 CO    HIGH WIND          979

[[10]]
# A tibble: 1 x 3
  state evtype            max.net.loss
  <fct> <fct>                    <dbl>
1 CT    THUNDERSTORM WIND         3200

[[11]]
# A tibble: 1 x 3
  state evtype    max.net.loss
  <fct> <fct>            <dbl>
1 DC    TSTM WIND          600

[[12]]
# A tibble: 1 x 3
  state evtype    max.net.loss
  <fct> <fct>            <dbl>
1 DE    LIGHTNING          800

[[13]]
# A tibble: 1 x 3
  state evtype max.net.loss
  <fct> <fct>         <dbl>
1 FL    FLOOD           935

[[14]]
# A tibble: 1 x 3
  state evtype    max.net.loss
  <fct> <fct>            <dbl>
1 GA    ICE STORM         952.

[[15]]
# A tibble: 1 x 3
  state evtype           max.net.loss
  <fct> <fct>                   <dbl>
1 GM    MARINE TSTM WIND          100

[[16]]
# A tibble: 1 x 3
  state evtype           max.net.loss
  <fct> <fct>                   <dbl>
1 GU    STORM SURGE/TIDE          900

[[17]]
# A tibble: 1 x 3
  state evtype   max.net.loss
  <fct> <fct>           <dbl>
1 HI    WILDFIRE          950

[[18]]
# A tibble: 1 x 3
  state evtype    max.net.loss
  <fct> <fct>            <dbl>
1 IA    ICE STORM          989

[[19]]
# A tibble: 1 x 3
  state evtype      max.net.loss
  <fct> <fct>              <dbl>
1 ID    FLASH FLOOD          800

[[20]]
# A tibble: 1 x 3
  state evtype      max.net.loss
  <fct> <fct>              <dbl>
1 IL    FLASH FLOOD         5000

[[21]]
# A tibble: 1 x 3
  state evtype max.net.loss
  <fct> <fct>         <dbl>
1 IN    FLOOD          3000

[[22]]
# A tibble: 1 x 3
  state evtype   max.net.loss
  <fct> <fct>           <dbl>
1 KS    WILDFIRE         1000

[[23]]
# A tibble: 1 x 3
  state evtype      max.net.loss
  <fct> <fct>              <dbl>
1 KY    FLASH FLOOD         3000

[[24]]
# A tibble: 1 x 3
  state evtype    max.net.loss
  <fct> <fct>            <dbl>
1 LA    ICE STORM          900

[[25]]
# A tibble: 3 x 3
  state evtype                   max.net.loss
  <fct> <fct>                           <dbl>
1 LC    MARINE HAIL                         0
2 LC    MARINE THUNDERSTORM WIND            0
3 LC    MARINE TSTM WIND                    0

[[26]]
# A tibble: 1 x 3
  state evtype                   max.net.loss
  <fct> <fct>                           <dbl>
1 LE    MARINE THUNDERSTORM WIND           25

[[27]]
# A tibble: 4 x 3
  state evtype                   max.net.loss
  <fct> <fct>                           <dbl>
1 LH    MARINE HAIL                         0
2 LH    MARINE THUNDERSTORM WIND            0
3 LH    MARINE TSTM WIND                    0
4 LH    WATERSPOUT                          0

[[28]]
# A tibble: 1 x 3
  state evtype           max.net.loss
  <fct> <fct>                   <dbl>
1 LM    MARINE TSTM WIND          500

[[29]]
# A tibble: 1 x 3
  state evtype           max.net.loss
  <fct> <fct>                   <dbl>
1 LO    MARINE TSTM WIND           25

[[30]]
# A tibble: 1 x 3
  state evtype           max.net.loss
  <fct> <fct>                   <dbl>
1 LS    MARINE TSTM WIND          400

[[31]]
# A tibble: 1 x 3
  state evtype    max.net.loss
  <fct> <fct>            <dbl>
1 MA    HIGH WIND          900

[[32]]
# A tibble: 2 x 3
  state evtype         max.net.loss
  <fct> <fct>                 <dbl>
1 MD    FLASH FLOOD             900
2 MD    TROPICAL STORM          900

[[33]]
# A tibble: 1 x 3
  state evtype max.net.loss
  <fct> <fct>         <dbl>
1 ME    FLOOD           954

[[34]]
# A tibble: 1 x 3
  state evtype    max.net.loss
  <fct> <fct>            <dbl>
1 MH    HIGH SURF            5

[[35]]
# A tibble: 1 x 3
  state evtype      max.net.loss
  <fct> <fct>              <dbl>
1 MI    FLASH FLOOD          970

[[36]]
# A tibble: 1 x 3
  state evtype max.net.loss
  <fct> <fct>         <dbl>
1 MN    FLOOD           996

[[37]]
# A tibble: 1 x 3
  state evtype max.net.loss
  <fct> <fct>         <dbl>
1 MO    FLOOD           940

[[38]]
# A tibble: 1 x 3
  state evtype max.net.loss
  <fct> <fct>         <dbl>
1 MS    FLOOD           955

[[39]]
# A tibble: 1 x 3
  state evtype max.net.loss
  <fct> <fct>         <dbl>
1 MT    HAIL            900

[[40]]
# A tibble: 1 x 3
  state evtype            max.net.loss
  <fct> <fct>                    <dbl>
1 NC    THUNDERSTORM WIND         5000

[[41]]
# A tibble: 1 x 3
  state evtype max.net.loss
  <fct> <fct>         <dbl>
1 ND    FLOOD           975

[[42]]
# A tibble: 1 x 3
  state evtype max.net.loss
  <fct> <fct>         <dbl>
1 NE    FLOOD           897

[[43]]
# A tibble: 1 x 3
  state evtype max.net.loss
  <fct> <fct>         <dbl>
1 NH    FLOOD           945

[[44]]
# A tibble: 2 x 3
  state evtype        max.net.loss
  <fct> <fct>                <dbl>
1 NJ    COASTAL FLOOD          900
2 NJ    FLOOD                  900

[[45]]
# A tibble: 1 x 3
  state evtype            max.net.loss
  <fct> <fct>                    <dbl>
1 NM    THUNDERSTORM WIND          800

[[46]]
# A tibble: 1 x 3
  state evtype max.net.loss
  <fct> <fct>         <dbl>
1 NV    FLOOD           973

[[47]]
# A tibble: 2 x 3
  state evtype    max.net.loss
  <fct> <fct>            <dbl>
1 NY    FLOOD              975
2 NY    TSTM WIND          975

[[48]]
# A tibble: 1 x 3
  state evtype    max.net.loss
  <fct> <fct>            <dbl>
1 OH    HIGH WIND          995

[[49]]
# A tibble: 1 x 3
  state evtype            max.net.loss
  <fct> <fct>                    <dbl>
1 OK    THUNDERSTORM WIND         3500

[[50]]
# A tibble: 1 x 3
  state evtype max.net.loss
  <fct> <fct>         <dbl>
1 OR    FLOOD           688

[[51]]
# A tibble: 5 x 3
  state evtype             max.net.loss
  <fct> <fct>                     <dbl>
1 PA    FLASH FLOOD                 900
2 PA    HEAVY SNOW                  900
3 PA    THUNDERSTORM WINDS          900
4 PA    TORNADO                     900
5 PA    WINTER STORM                900

[[52]]
# A tibble: 3 x 3
  state evtype             max.net.loss
  <fct> <fct>                     <dbl>
1 PH    MARINE STRONG WIND            0
2 PH    MARINE TSTM WIND              0
3 PH    WATERSPOUT                    0

[[53]]
# A tibble: 1 x 3
  state evtype           max.net.loss
  <fct> <fct>                   <dbl>
1 PK    MARINE HIGH WIND           15

[[54]]
# A tibble: 1 x 3
  state evtype     max.net.loss
  <fct> <fct>             <dbl>
1 PM    WATERSPOUT            0

[[55]]
# A tibble: 1 x 3
  state evtype    max.net.loss
  <fct> <fct>            <dbl>
1 PR    LANDSLIDE         4800

[[56]]
# A tibble: 1 x 3
  state evtype             max.net.loss
  <fct> <fct>                     <dbl>
1 PZ    MARINE STRONG WIND           25

[[57]]
# A tibble: 1 x 3
  state evtype    max.net.loss
  <fct> <fct>            <dbl>
1 RI    TSTM WIND          750

[[58]]
# A tibble: 1 x 3
  state evtype  max.net.loss
  <fct> <fct>          <dbl>
1 SC    TORNADO         1000

[[59]]
# A tibble: 1 x 3
  state evtype  max.net.loss
  <fct> <fct>          <dbl>
1 SD    TORNADO          900

[[60]]
# A tibble: 1 x 3
  state evtype           max.net.loss
  <fct> <fct>                   <dbl>
1 SL    MARINE TSTM WIND           15

[[61]]
# A tibble: 1 x 3
  state evtype       max.net.loss
  <fct> <fct>               <dbl>
1 ST    STRONG WINDS            0

[[62]]
# A tibble: 1 x 3
  state evtype  max.net.loss
  <fct> <fct>          <dbl>
1 TN    TORNADO         4410

[[63]]
# A tibble: 1 x 3
  state evtype    max.net.loss
  <fct> <fct>            <dbl>
1 TX    TSTM WIND          990

[[64]]
# A tibble: 2 x 3
  state evtype       max.net.loss
  <fct> <fct>               <dbl>
1 UT    FLASH FLOOD           900
2 UT    WINTER STORM          900

[[65]]
# A tibble: 1 x 3
  state evtype      max.net.loss
  <fct> <fct>              <dbl>
1 VA    FLASH FLOOD          900

[[66]]
# A tibble: 2 x 3
  state evtype     max.net.loss
  <fct> <fct>             <dbl>
1 VI    HEAVY RAIN          500
2 VI    HIGH WINDS          500

[[67]]
# A tibble: 1 x 3
  state evtype      max.net.loss
  <fct> <fct>              <dbl>
1 VT    FLASH FLOOD          800

[[68]]
# A tibble: 3 x 3
  state evtype           max.net.loss
  <fct> <fct>                   <dbl>
1 WA    FLOOD                     900
2 WA    LIGHTNING                 900
3 WA    WILD/FOREST FIRE          900

[[69]]
# A tibble: 1 x 3
  state evtype max.net.loss
  <fct> <fct>         <dbl>
1 WI    FLOOD           975

[[70]]
# A tibble: 1 x 3
  state evtype      max.net.loss
  <fct> <fct>              <dbl>
1 WV    FLASH FLOOD          950

[[71]]
# A tibble: 1 x 3
  state evtype max.net.loss
  <fct> <fct>         <dbl>
1 WY    HAIL            800

[[72]]
# A tibble: 1 x 3
  state evtype                   max.net.loss
  <fct> <fct>                           <dbl>
1 XX    MARINE THUNDERSTORM WIND            0
library(dplyr)
df$state <- factor(df$state, levels = unique(df$state))
df2 <- group_split(df)