How do I create a print function in R?

Fire

The following is my data,

Number Score
0.00 4.00
0.31 2.07
0.63 2.15
0.94 3.08
1.26 4.09
1.57 2.39
1.88 1.96
2.20 3.72

I want to create a function that on output gives me,

Scores by Number (z = 8)

Number Score
0.00 4.00
0.31 2.07
0.63 2.15
0.94 3.08
1.26 4.09

5 more rows

I know that the skeleton of the function should look something like this, but I've never dealt with also providing words/phrases on output.

print <- function(x, ...)
{

}
akrun

We can use paste, cat, print to print the output

print_new <- function(dat) {
      nr <- nrow(dat)
      n <- 5
      n1 <- nr - n
      cat(sprintf("Scores by Number (z = %d)", nr), "\n")
      cat('', '\n')
      print(head(dat, n))
      cat('', '\n')
      cat(sprintf('%d more rows', n1))




  }

print_new(df1)
#Scores by Number (z = 8) 

#  Number Score
#1   0.00  4.00
#2   0.31  2.07
#3   0.63  2.15
#4   0.94  3.08
#5   1.26  4.09

#3 more rows

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

How do I print entire number in Python from describe() function?

How do I create an XPath function in Groovy

How do I print return value of a function?

How do I create a noexcept function pointer?

How do I print variables from inside a function?

How do I create a "macro" for regressors in R?

How do I print the variable values that result in the maximum of a function?

How do I print the original string for JavaScript function

How do I create a list of functions in R?

How do i print the reverse of name in python without using function?

How do I make scanf function print whole array

How do I create a flatlist function in ML?

How do I create a chained mean in R?

How do I print an __init__() inside of a function?

How do I get my function to print my code?

How do I put this code into one print function (or line)?

How do I get a callback function to print something only periodically?

How do I create a loop to print the following pattern?

How do I create a jquery function with callbacks

How do I create a function with a function in Python?

How do I create a bar graph in r?

How do I create a program to print titles with certain keywords?

How do I create a constructor function in R?

How to create a print function in python

How do I add the result of a print function ito a list

How do I create this function correctly?

how do i print iterations in fitness function

How do I create a HashMap with value of function?

How do I create code snippets for vscode for "print_r" that outputs the contents of the variable passed to it, along with the filename ,line number