Ram
Ram

Reputation: 331

Append lines of text above or below the dataframe in r

I have a huge data frame (dimension:600000 X 6). All 6 columns are integer values representing different features for each row. I would like to add three lines of text either above or below the data frame which are common to all the rows. Is it possible to insert some lines of text below or above the data frame?

For example: Given a dataframe,

    name<-letters[1:10]
    length<-c(140,50,25,120,156,146,180,98,120,110)
    quality<-c(20,25,35,20,15,28,32,35,29,25)
    df<-data.frame(name,length,quality)

how to insert three lines of text either above or below the data frame,df:

    No. of reads = 10
    %AT=32
    %GC=30

The output should look like:

      name length quality
   1     a    140      20
   2     b     50      25
   3     c     25      35
   4     d    120      20
   5     e    156      15
   6     f    146      28
   7     g    180      32
   8     h     98      35
   9     i    120      29
   10    j    110      25
   No. of reads = 10
   %AT=32
   %GC=30

Upvotes: 1

Views: 2073

Answers (1)

gwatson
gwatson

Reputation: 488

Are you looking for something like this?

prettyprint <- function() {
  print(df)
  cat("No. of reads = 10",
      "\n%AT=32",
      "\n%GC=30")
 }
 prettyprint()

The output looks something like this:

   name length quality
1     a    140      20
2     b     50      25
3     c     25      35
4     d    120      20
5     e    156      15
6     f    146      28
7     g    180      32
8     h     98      35
9     i    120      29
10    j    110      25
No. of reads = 10 
%AT=32 
%GC=30

Upvotes: 6

Related Questions