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

Source: Internet
Author: User

Split Data.frame by the value of a column

My data is like this (for example):

ID  Rate    State1   24 AL2 35 MN3 46 FL4 34 AL5 78 MN6 99 FL

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

data set 1ID Rate State1 24 AL4 34 ALdata set 2ID Rate State2 35 MN5 78 MNdata set 3ID Rate State3 46 FL6 99 FL


Split(DF,DF$ State)
$AL
ID Rate State
1124AL
4434AL

$FL
ID Rate State
3 3 FL
6 6 FL

$MN
ID Rate State
2 2 MN
5 5 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

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.