Save File after order

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Save File after order

MSousa
Hello,

    I'm trying to write the sorted data in a file of a data.frame, My question and my problem is that when I record in file adds a new column row.name, which apparently is the original position in the file.
    I wanted to write to the file without this column

x<-data.frame(name="x1",Time=20)
x<-rbind(x,data.frame(name="x2",Time=25))
x<-rbind(x,data.frame(name="x3",Time=23))
x<-rbind(x,data.frame(name="x2",Time=45))
x<-rbind(x,data.frame(name="x1",Time=25))
x<-rbind(x,data.frame(name="x1",Time=55))

x<-x[order(x$name),]
View(x)
write.csv(data.frame(x$name,x$Time), file = "~/Desktop/DatasetOrder.csv")
In this momment save this
  name Time
1   x1   20
5   x1   25
6   x1   55
2   x2   25
4   x2   45
3   x3   23

The ideia is save
name Time
x1   20
x1   25
x1   55
x2   25
x2   45
x3   23

Thanks
Reply | Threaded
Open this post in threaded view
|

Re: Save File after order

Sarah Goslee
It doesn't have anything to do with your use of order(). Those are the
row names of your data frame. You can disable writing them with the
row.names=FALSE argument to write.table().

Sarah

On Mon, Mar 19, 2012 at 8:16 AM, MSousa <[hidden email]> wrote:

> Hello,
>
>     I'm trying to write the sorted data in a file of a data.frame, My
> question and my problem is that when I record in file adds a new column
> row.name, which apparently is the original position in the file.
>     I wanted to write to the file without this column
>
> x<-data.frame(name="x1",Time=20)
> x<-rbind(x,data.frame(name="x2",Time=25))
> x<-rbind(x,data.frame(name="x3",Time=23))
> x<-rbind(x,data.frame(name="x2",Time=45))
> x<-rbind(x,data.frame(name="x1",Time=25))
> x<-rbind(x,data.frame(name="x1",Time=55))
>
> x<-x[order(x$name),]
> View(x)
> write.csv(data.frame(x$name,x$Time), file = "~/Desktop/DatasetOrder.csv")
> In this momment save this
>  name Time
> 1   x1   20
> 5   x1   25
> 6   x1   55
> 2   x2   25
> 4   x2   45
> 3   x3   23
>
> The ideia is save
> name Time
> x1   20
> x1   25
> x1   55
> x2   25
> x2   45
> x3   23
>
> Thanks
>

--
Sarah Goslee
http://www.functionaldiversity.org

______________________________________________
[hidden email] 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 | Threaded
Open this post in threaded view
|

Re: Save File after order

MSousa
Thanks