How to write lines to a text file in R

0 votes

In R programming Language, how do I write lines to a text file?

Hello

World

This text to written in a text file named "abc.txt"?

Apr 16, 2018 in Data Analytics by DataKing99
• 8,250 points
19,077 views

3 answers to this question.

0 votes

It is easy and simple:

fileConn<-file("abc.txt")
writeLines(c("Hello","World"), fileConn)
close(fileConn)
answered Apr 16, 2018 by DeepCoder786
• 1,720 points
Thanks, it works!!
+1 vote
sink("outfile.txt")
cat("hello")
cat("\n")
cat("world")
sink()
answered May 24, 2019 by anonymous
0 votes
Hi,

In R programming Language, How I write lines to a text file?

I would use the cat() command as in this example:

> cat("Hello",file="outfile.txt",sep="\n")

> cat("World",file="outfile.txt",append=TRUE)

You can then view the results from with R with

> file.show("outfile.txt")

hello

world.  Try This It will Help You. Thank You
answered Nov 29, 2019 by Akashraj
• 260 points
1 flag

Related Questions In Data Analytics

0 votes
1 answer

How to import and clean a text file into dataframe in R?

You can use readLines() or read.table() depending ...READ MORE

answered Jul 16, 2019 in Data Analytics by anonymous
6,517 views
0 votes
1 answer

How to write a custom function which will replace all the missing values in a vector with the mean of values in R?

Consider this vector: a<-c(1,2,3,NA,4,5,NA,NA) Write the function to impute ...READ MORE

answered Jul 4, 2018 in Data Analytics by CodingByHeart77
• 3,750 points
4,596 views
0 votes
1 answer

How can I import a file in R without giving the destination/file path to the specified file?

You can use the window explorer to ...READ MORE

answered Aug 28, 2018 in Data Analytics by Abhi
• 3,720 points

edited Aug 28, 2018 by Vardhan 3,037 views
0 votes
2 answers

How to create a table in R without external file?

Tibble also creates a table-like structure. Use below ...READ MORE

answered Sep 3, 2019 in Data Analytics by anonymous
• 33,030 points
3,057 views
0 votes
1 answer

How to check if a file already exists or not in R?

Check out file.exists() function!! The function file.exists() returns a ...READ MORE

answered Oct 29, 2019 in Data Analytics by Cherukuri
• 33,030 points
68,219 views
0 votes
1 answer

How to read a CSV file in R?

Hi@akhtar, You can read your CSV file in ...READ MORE

answered Oct 29, 2020 in Data Analytics by MD
• 95,460 points
718 views
0 votes
1 answer

By using dpylr package sum of multiple columns

Basically here we are making an equation ...READ MORE

answered Apr 5, 2018 in Data Analytics by DeepCoder786
• 1,720 points
2,268 views
0 votes
1 answer

How to convert a text mining termDocumentMatrix into excel or csv in R?

By assuming that all the values are ...READ MORE

answered Apr 5, 2018 in Data Analytics by DeepCoder786
• 1,720 points
1,963 views
0 votes
1 answer

In a dpylr pipline how to use sample and seq?

For avoiding rowwise(), I prefer to use ...READ MORE

answered Apr 6, 2018 in Data Analytics by DeepCoder786
• 1,720 points

edited Jun 9, 2020 by Gitika 1,201 views
0 votes
1 answer

How to create a list of Data frames?

Basically all we have to do is ...READ MORE

answered Apr 9, 2018 in Data Analytics by DeepCoder786
• 1,720 points
1,397 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP