Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Read csv file into R that contains brackets at at the start and end of each line

Tags:

r

csv

I have a text file that looks as follows

(abc,123)
(def,456)
(ghi,789)
...

In R, I would like to read this file as a csv. Therefore I need to get rid of the opening and closing brackets at the end of the lines. Do you have an idea how to achieve that?

Reading the file, removing the brackets and writing to a temporary file should be avoided if possible.

like image 232
Frederic Avatar asked Jul 07 '14 14:07

Frederic


1 Answers

Ok, this seems to work (on my Mac):

read.table(pipe("tr -d '()' < ~/Desktop/paren.txt"),header = FALSE,sep = ",")
   V1  V2
1 123 abc
2 456 def
3 789 ghi
like image 78
joran Avatar answered Nov 15 '22 14:11

joran