Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

r - Use tab as part of seperator

Tags:

string

r

I am trying to print a string followed by ": [tab]" and then a number. The relevant part of my code looks like:

print(paste("Name",5, sep=":\t"))

But this gives me

"Name:\t5"

. I have tried:

print(paste("Name",5, sep=cat(":\t")))

but this gives me:

Error in paste("Name", 5, sep = cat(":\t")) : 
  invalid separator

I'm pretty sure the problem is related to the issue discussed in this email thread but I don't understand the solution.

like image 645
Adam_G Avatar asked Sep 06 '15 18:09

Adam_G


People also ask

How do you set a tab delimiter in R?

The way to tell R that you mean the tab character is to say "\t" .

How do you read tab separated values?

To read tab-separated values files with Python, we'll take advantage of the fact that they're similar to CSVs. We'll use Python's csv library and tell it to split things up with tabs instead of commas. Just set the delimiter argument to "\t" . That's it!

How do I load a tab file in R?

First, as with many things in R, there are many ways of bringing data into your workspace. A flexible way to import data is to click on the Environment tab in the upper right window of RStudio and then click the Import Dataset tab. Multiple file type options are shown, such as text, Excel, SPSS, SAS, and Stata.


1 Answers

You can go as follows:

cat("Name","\t", 5, "\n")

When you need help on a function, just type in the name of that function in your R GUI preceded by ?, eg ?cat.

like image 185
tagoma Avatar answered Sep 28 '22 08:09

tagoma