0% found this document useful (0 votes)
31 views9 pages

R Exporting Data From R 27-3-2020 (Part 2)

Uploaded by

ADITI NEGI
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views9 pages

R Exporting Data From R 27-3-2020 (Part 2)

Uploaded by

ADITI NEGI
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

TMC 204

Statistical Data Analysis with R


Unit 3
Exporting Data from R(Part 2)

Presented By : Aditya Joshi


Asst. Professor
Department of Computer Application
Graphic Era Deemed to be University
27-03-2020
paste()
Description:
paste() converts its arguments to character strings and concatenates them.

Syntax:
paste(…, sep=“”, collapse=NULL)

Returns:
Character Vector

Documentation:
help(paste)
Example 1:
> x<-1:10
> paste(x)
[1] "1" "2" "3" "4" "5" "6" "7" "8" "9" "10"
> paste(x,collapse="NULL")
[1] "1NULL2NULL3NULL4NULL5NULL6NULL7NULL8NULL9NULL10"
> paste(x,collapse="")
[1] "12345678910"

Example 2:
> x<-LETTERS
>x
[1] "A" "B" "C" "D" "E" "F" "G" "H" "I" "J" "K" "L" "M" "N" "O"
[16] "P" "Q" "R" "S" "T" "U" "V" "W" "X" "Y" "Z"
> paste(x)
[1] "A" "B" "C" "D" "E" "F" "G" "H" "I" "J" "K" "L" "M" "N" "O"
[16] "P" "Q" "R" "S" "T" "U" "V" "W" "X" "Y" "Z"
> paste(x,collapse="")
[1] "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
Example 3:
> name<-"Aditya"
> age<-35
> paste(name,age)
[1] "Aditya 35"
> paste(name,age,sep=",")
[1] "Aditya,35"
> paste(name,age,sep="")
[1] "Aditya35“

Example 4:
> alpha<-LETTERS[1:4]
> numeric<-1:4
> alpha_numeric<-paste(alpha,numeric)
> alpha_numeric
[1] "A 1“ "B 2" "C 3" "D 4“
> alpha_numeric<-paste(alpha,numeric,sep="")
> alpha_numeric
[1] "A1" "B2" "C3" "D4"
paste0()
Description:
paste0() it does a same job as paste() but with a blank seperator.

Syntax:
paste0(…, collapse=NULL)

Returns:
Character Vector of concatenated values

Documentation:
help(paste0)
Example 1:
> alpha<-LETTERS[1:4]
> numeric<-1:4
> alpha_numeric<-paste0(alpha,numeric)
> alpha_numeric
[1] "A1" "B2" "C3" "D4“

Example 2:
> name<-"Aditya"
> age<-35
> paste0(name,age)
[1] "Aditya35"
> paste(name,age)
[1] "Aditya 35“
> paste(name,age,sep="")
[1] "Aditya35"
sprintf()
Description:
sprintf() it returns a character vector containing text and objects

Syntax:
sprintf()(fmt, …)

Returns:
Character Vector

Documentation:
help(sprintf)
Example 1:
> name<-"Aditya"
> age<-35
> sprintf("your name is %s and you are %d years old",name,age)
[1] "your name is Aditya and you are 35 years old“

%s is replaced by value in name and %d is replaced by value in age


s indicates string type and d indicated integer type
Output Data to file
In this section we will learn the use of following functions in next
lecture :
• writeLines
• write
• write.table
• write.csv
• sink
• dump

Sources of lecture: Slideshare:r-squared.in

You might also like