[R] Help with writing data to csv
David L Carlson
dcarlson at tamu.edu
Mon May 14 18:11:39 CEST 2012
If you have a data.frame and you want a table in Microsoft Word, the
quickest path (without additional packages and assuming you are using
Windows) is
write.table(DataFrameName, file="clipboard", sep="\t", row.names=FALSE)
# If the file is large, you may need "clipboard-128" instead of "clipboard."
Now open Microsoft Excel and select Paste. You now have the data.frame in
Excel. Select the data and copy it. Now open Microsoft Word and select
Paste. You now have the data.frame in Word as a table.
If you need something more flexible, look at packages xlsx, xlsReadWrite,
and R2wd.
----------------------------------------------
David L Carlson
Associate Professor of Anthropology
Texas A&M University
College Station, TX 77843-4352
> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-
> project.org] On Behalf Of DL
> Sent: Saturday, May 12, 2012 3:33 PM
> To: r-help at r-project.org
> Subject: [R] Help with writing data to csv
>
> I am trying to write data to csv but I am having issues with the
> separations.
>
> Basically I have some results that I get with R that I copied and
> pasted
> into word and then saved as .txt
>
> I want to write the results to csv because it's easier to make tables
> in
> word (all I would have to do is copy and paste into a table, instead of
> typing everything out).
>
> I am able to write the data to the .csv file but the data is not
> comma-delimited when I open the file. Everything is written into the
> first
> cell.
>
> These are the various commands that I have been inputting:
>
> write.csv(practice, file.choose(new=T), quote=F, row.names=F)
>
> write.csv(practice, file.choose(new=T), sep=",", quote=F, row.names=F)
> Warning message:
> In write.csv(practice, file.choose(new = T), sep = ",", quote = F, :
> attempt to set 'sep' ignored
>
> write.table(practice, file =
> "C:/Users/User/Documents/Documents/Proyectodeafroantillanos/Laterals/pr
> actice.csv",
> sep="\t", quote=F, row.names=F)
>
> write.csv(practice, file =
> "C:/Users/User/Documents/Documents/Proyectodeafroantillanos/Laterals/pr
> actice.csv")
>
> > write.csv(practice, file =
> >
> "C:/Users/User/Documents/Documents/Proyectodeafroantillanos/Laterals/pr
> actice.csv",
> > row.names=FALSE)
>
> write.csv(practice, file =
> "C:/Users/User/Documents/Documents/Proyectodeafroantillanos/Laterals/pr
> actice.csv",
> sep = "\t", row.names=FALSE)
> Warning message:
> In write.csv(practice, file =
> "C:/Users/User/Documents/Documents/Proyectodeafroantillanos/Laterals/pr
> actice.csv",
> :
> attempt to set 'sep' ignored
>
>
> As you can see, the commands in which I write to csv and set "sep" I
> get a
> message saying that attempt to set "sep" ignored. All the other
> commands
> work but I don't get a comma-delimited nor a tab-delimited file.
>
> Am I doing something wrong?
>
> Thank you.
>
> --
> View this message in context: http://r.789695.n4.nabble.com/Help-with-
> writing-data-to-csv-tp4629436.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help at 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.
More information about the R-help
mailing list