Dataframe reshaping based on column count

I have a 2 column 100,000 row dataframe that looks as follows:

Count               String
3                 "Hello World"
2                  "Hi John"
1                  "Dear Joe"

I want to reshape this dataframe into a 1 column dataframe, removing the count and instead adding the repeating items. E.g.,

String 
"Hello World"
"Hello World"
"Hello World"
"Hi John"
"Hi John"
"Dear Joe"

Answers


Try

one_col_df <- data.frame(String = rep(df$String, df$Count))

What is going on there is that for each String, the function rep will repeat Count times, respecting their order in vector.


Need Your Help

Listeneing for changes in JCheckBox in a JTable

java swing jtable jcheckbox

How do I listen for changes in a JTable column that has a JCheckBox in it? I want to know when the user selects/deselects the check box. The class for the column is set as boolean so it is automati...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.