R Tutorials by
: Er Karan Arora : Founder & CEO - ITRONIX SOLUTIONS¶1: Cat function in R
¶cat function in R will combine character values and print them to the screen or save them in a file directly. The cat function coerces its arguments to character values, then concatenates and displays them. This makes the function ideal for printing messages and warnings from inside of functions
cat(… , file = “”, sep = ” “, fill = FALSE, labels = NULL, append = FALSE)
…
one or more R objects, to be concatenated together.sep
a character string to separate the terms.collapse
an optional character string to separate the results.The cat function will convert the values into character values then combine those values and print them
cat('one',2,'three',4,'five')
cat(1:10,sep="\t")
cat(1:10,sep="\n")
cat(1:10,file="num_series.csv",sep="\n",append ="FALSE")
cat(1:10,file="num_series.csv",sep=",",append ="FALSE")
cat(1:10,file="num_series.csv",sep="\n")
cat(11:20,file="num_series.csv",sep="\n",append ="TRUE")
2: Paste function in R
¶Paste function in R is used to concatenate Vectors by converting them into character. paste0 function in R simply concatenates the vector with space separator. lets see an example of paste() Function in R and Paste0() Function in R
…
one or more R objects, to be concatenated together.sep
a character string to separate the terms.collapse
an optional character string to separate the results.In its simplest usage, paste function in R will accept an unlimited number of scalars, and join them together, separating each scalar with a space by default
paste('one',2,'three',4,'five')
paste('X',1:5,sep='')
paste(c('one','two','three','four'),collapse=' and ')
paste(c('X','Y'),1:5,sep='_',collapse=' and ')
3: Paste0() Function in R
¶Paste0() is a simple paste() function with default separator “ ”. paste0() Function will take only two arguments as shown below
paste0('X',1:5)
paste0('X',1:5,collapse=",")