Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9145201
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T10:27:20+00:00 2026-06-17T10:27:20+00:00

I have a data frame which I would like to write it to a

  • 0

I have a data frame which I would like to write it to a pdf file in organized fashion.

For example, my df looks like this:

Date    County    Trade
1/1/2012  USA     5
1/1/2012  Japan   4
1/2/2012  USA     10
1/3/2012  Germany 15

I would like to output to be group by Date, place a space or line break after each group;

I have this piece of code but this prints out everything to the pdf file without grouping:

library(gridExtra)
pdf("trade.pdf", height=11, width=8.5)
grid.table(df)
dev.off()

Any ideas how can best present this data set in a pdf file with grouping on Date? I like to use grid.Extra. Anybody knows how to put a title to grid.Extra?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T10:27:21+00:00Added an answer on June 17, 2026 at 10:27 am

    This code should work:

    library(gridExtra)
    
    df <- read.table(text = 
    "1/1/2012  USA     5
    1/1/2012  Japan   4
    1/2/2012  USA     10
    1/3/2012  Germany 15"
    )
    names(df) <- c("Date","Country","Trade")
    
    EqDatedf <- as.data.frame(df[1,])
    EmptyLine <- data.frame(Date = "",Country = "",Trade = "")
    
    pdf(file = "q.pdf")
    
    for (i in 2:nrow(df)) 
    {
    if (as.vector(df$Date[i])  ==  as.vector(df$Date[i-1])) 
    {EqDatedf <- rbind(EqDatedf, df[i,])}
    
    else {
    EqDatedf <- rbind(EqDatedf, EmptyLine)
    EqDatedf <- rbind(EqDatedf, df[i,]) 
         }
    }
    
    grid.table(EqDatedf, show.rownames = FALSE)
    dev.off()
    

    enter image description here

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following question: I have data frame which looks like this. I
I have a 3 column data frame which looks a little like this: id
I have the following data frame from which I would like to extract rows
For a data frame populated from a SQL query which looks like this: Company
I have got a data frame (which is called data.set.y). And I would like
I have a large data frame with date variables, which reflect first day of
I have a data frame for which I'm computing a linear model and would
I have a number of operations on data frames which I would like to
I have a data frame like this (specifically the data.frame contains 50 columns): G1
I have a data.frame (which I melted using the melt function), from which I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.