0

I have loaded a csv file using read.csv. This has 18 columns and 9000+ rows.

Out of these I am specifically trying to work with two columns: 1) Date, which has date. 2) review text, which has a few lines of text per entry and is a list.

I have extracted these two columns seperately from the CSV and am trying to combine them together to get an object that looks like

Date            review_text
2009-01-01        " This is good"
2010-01-01        "Was a great experience"

and so on. I have tried using c, paste and also cbind, but am unable to combine these two objects. Please let me know if you have any suggestions. On a related note, once I combine these, I am trying to sort the resulting object by date, to group the entries by quarter, so what would be the best object to put this into? Please advice. Thanks!

Sotos
  • 51,121
  • 6
  • 32
  • 66
FlyingPickle
  • 1,047
  • 1
  • 9
  • 19
  • Please provide a [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). This will make it easier for others to assist you. – shrgm May 21 '16 at 06:45
  • Also, look up `data.frame` which is the object your data should be in, and `order` which would allow you to sort your data. – shrgm May 21 '16 at 07:02

1 Answers1

0

This would be my solution, with the lubridate and dplyr packages:

library(dplyr)
library(lubridate)

set.seed(123)
reviews <- data.frame(
  date = as.Date("2016-05-21") - runif(100, 0, 365),
  text = paste("Test", 1:100)
)

output <- reviews %>%
  arrange( date ) %>%
  group_by( dyear = year( date ), dQ = quarter( date ) ) %>%
  summarise(
    output = paste( paste( date, text ), collapse = ":::")
  ) %>%
  ungroup() %>%
  arrange( dyear, dQ )

Output is a bit hard to post, because the character parts are really long. That brings me to the most important questions: why would you want to do this?

Edit: oh, your clarification of your question made this answer irrelevant. Take a look at the merge function, but it's hard to provide anything when you don't give a reproducible example so we know your data structure.
Good luck!

Jasper
  • 555
  • 2
  • 12