• In R, how to split/subset a data frame by factors in one column?


    按照某列的值拆分data.frame

    My data is like this (for example):

    ID  Rate    State
    1   24  AL
    2   35  MN
    3   46  FL
    4   34  AL
    5   78  MN
    6   99  FL

    I want to split the data by state and I want to get 3 data sets like below:

    data set 1
    ID  Rate    State
    1   24  AL
    4   34  AL
    data set 2
    ID  Rate    State
    2   35  MN
    5   78  MN
    data set 3
    ID  Rate    State
    3   46  FL
    6   99  FL


    split( df , df$State )
    $AL
      ID Rate State
    1  1   24    AL
    4  4   34    AL

    $FL
      ID Rate State
    3  3   46    FL
    6  6   99    FL

    $MN
      ID Rate State
    2  2   35    MN
    5  5   78    MN



    mylist <- split( df , df$State ) ;
    mylist[[1]]

    mylist[[2]]
    mylist[[3]]

    REF:
    http://stackoverflow.com/questions/19327020/in-r-how-to-split-subset-a-data-frame-by-factors-in-one-column
  • 相关阅读:
    树的可视化
    图的可视化
    1+1=2
    用xapian来做索引
    学习的快乐
    项目小结
    z=sin(xy)
    Min Stack
    互联网公司的文化
    为什么要读数学书
  • 原文地址:https://www.cnblogs.com/emanlee/p/4463570.html
Copyright © 2020-2023  润新知