This site uses cookies to deliver our services and to show you relevant ads and job listings.
By using our site, you acknowledge that you have read and understand our Cookie Policy, Privacy Policy, and our Terms of Service.
Your use of Stack Overflow’s Products and Services, including the Stack Overflow Network, is subject to these policies and terms.

Join us in building a kind, collaborative learning community via our updated
Code of Conduct.

Hey greg , I couldn't understand the syntax for the sample command , can you explain it.
– AnirudhFeb 1 '15 at 9:45

"You may also want to cut the data frame into an arbitrary number of smaller dataframes. Here, we cut into two dataframes." How is this an arbitrary number of data frames if you are specifying two dataframes here?
– user5359531Mar 16 '16 at 17:09

I suggested dlply first, but it didn't automatically name the entries by the grouping variable. I don't know what I did first, but aparently daply doesn't work unless a function is specified. I edited the answer to work.
– JoFrhwldJul 21 '10 at 21:03

The answer you want depends very much on how and why you want to break up the data frame.

For example, if you want to leave out some variables, you can create new data frames from specific columns of the database. The subscripts in brackets after the data frame refer to row and column numbers. Check out Spoetry for a complete description.

newdf <- mydf[,1:3]

Or, you can choose specific rows.

newdf <- mydf[1:3,]

And these subscripts can also be logical tests, such as choosing rows that contain a particular value, or factors with a desired value.

What do you want to do with the chunks left over? Do you need to perform the same operation on each chunk of the database? Then you'll want to ensure that the subsets of the data frame end up in a convenient object, such as a list, that will help you perform the same command on each chunk of the data frame.