In R, how to split/subset a data frame by factors in one column?
2015-04-28 17:24
543 查看
按照某列的值拆分data.frame
My data is like this (for example):
I want to split the data by state and I want to get 3 data sets like below:
mylist[[2]]
mylist[[3]]
REF: http://stackoverflow.com/questions/19327020/in-r-how-to-split-subset-a-data-frame-by-factors-in-one-column[/code]
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[/code]
相关文章推荐
- A useful function which used to split data by ',' from one column
- how to compile source code of "Data Structures & Algorithm Analysis in Java" writen by Mark Allen Weiss
- How To Split column In SQL
- select rows by values in a column from Dataframe
- How to merge blank cells in one column in Office Excel?
- How to use insert or retrieve data by using Core Data in iOS
- 《How to run one script by command line in 3dsMax》
- how to select data in multiple datatables after using join,group by and order by in Linq
- How To Commit Just One Data Block Changes In Oracle Forms
- How to Get the Frequency Table of a Categorical Variable as a Data Frame in R
- 【跟着stackoverflow学Pandas】How to iterate over rows in a DataFrame in Pandas-DataFrame按行迭代
- 【跟着stackoverflow学Pandas】 - Adding new column to existing DataFrame in Python pandas - Pandas 添加列
- Fast ways in R to get the first row of a data frame grouped by an identifier
- How to read one column from SQLite and store in Array
- Using JoinColumn, JPA using oneToMany mappedBy
- How to first sort by one attribute, if equal, then sort by another attribute.
- How to split string in Thymeleaf
- How to decode a H.264 frame on iOS by hardware decoding?
- nrf51822 secure DFU by OTA: How to Set Password in the DFU zip File
- How to split a string in C++