Hi Elham,

>From the (\t), It looks like the data in your data.txt file is
tab-delimited. To take care of that, set the separator string to be: "sep =
'\t' " instead of "," when you read in the file.

text <- read.table(file = "data.txt", sep = "\t")
text
write.table(text, "textfile.csv", row.names = F, col.names = F, sep =",")

Richard


On Fri, Dec 13, 2013 at 7:34 AM, Patty Haaem <elham_h...@yahoo.com> wrote:

> Hi every one,
> I have a text file like this:
> 1    4   4    1    6    23
> 1   4    2    2    3    28
> 1    4    5    1    2    24
> 1    2    3    1    1    24
> 1   2    3    1    2     40
> 1   2   3    1    4      22
>
> I want to separate columns by comma, like this:
> 1,4,4,1,6,23
> 1,4,2,2,3,28
> 1,4,5,1,2,24
> 1,2,3,1,1,24
> 1,2,3,1,2,40
> 1,2,3,1,4,22
>
> I used this code:
> mydata=read.table("data.txt",sep=",")
> but I see this output:
> 1\t4\t4\t1\t6\t231\t4\t2\t2\t3\t28
> ...
> please correct my code
> Thanks in advance
> Elham
>
>         [[alternative HTML version deleted]]
>
>
> ______________________________________________
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
>

        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to