Tuesday 30 June 2015

R : dput : Write an object to a file

“dput” function writes ASCII representation of an object to a file (or) connection.

Syntax
dput(x, file = "",
     control = c("keepNA", "keepInteger", "showAttributes"))


Parameter
Description
x
Object to be written to a file.
file
Represents a file (or) a connection.
control
Character vector specifies de-parsing options

> table1 = data.frame(id=1:4, firstName=c("Hari Krishna","Joel","Rama Krishna","Sudheer"))
> dput(table1, "out.R")
> 
> list.files()
[1] "dump.txt"     "employee.csv" "employee.txt" "myFunction.R" "out.R"        "output.txt"  

“out.R” contains following data

structure(list(id = 1:4, firstName = structure(1:4, .Label = c("Hari Krishna",
"Joel", "Rama Krishna", "Sudheer"), class = "factor")), .Names = c("id",

"firstName"), row.names = c(NA, -4L), class = "data.frame")



Prevoius                                                 Next                                                 Home

No comments:

Post a Comment