Quantcast

Using write.table i have a table with two columns i would like to save it as an excel file

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Using write.table i have a table with two columns i would like to save it as an excel file

kevin123
Using write.table i would like to save data  as an excel file to a folder. I am not too sure how to write the file path or what to name the file. I would appreciate any feedback.


> write.table(x, file = "", append = FALSE, quote = TRUE, sep = " ",
+             eol = "\n", na = "NA", dec = ".", row.names = TRUE,
+             col.names = TRUE, qmethod = c("escape", "double"),
+             fileEncoding = "")
"area" "bedrooms" "sale.price"

"9" 694 4 192
"10" 905 4 215
"11" 802 4 215
"12" 1366 4 274
"13" 716 4 112.7
"14" 963 4 185
"15" 821 4 212
"16" 714 4 220
"17" 1018 4 276
"18" 887 4 260
"19" 790 4 221.5
"20" 696 5 255
"21" 771 5 260
"22" 1006 5 293
"23" 1191 6 375
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Using write.table i have a table with two columns i would like to save it as an excel file

Michael Weylandt
I'd suggest you should probably just use the simpler write.csv() function to
make a file type that will move much more conveniently between Excel and R.

The syntax is:

write.csv(ThingBeingSaved, "filename.csv")

If you only put the file name to write.csv it will be placed in your working
directory, which you can find by running getwd() at the command line. If you
put a whole path, R will put it there. If you want to change your working
directory, setwd() can do that.

As to what to name the file, well -- that's your problem, but it can be
basically anything you want as long as it ends in ".csv". (It doesn't even
technically have to do that, but please do -- it will make your life better
when dealing with Excel)

Michael

On Thu, Aug 25, 2011 at 12:58 PM, kevin123 <[hidden email]> wrote:

> Using write.table i would like to save data  as an excel file to a folder.
> I
> am not too sure how to write the file path or what to name the file. I
> would
> appreciate any feedback.
>
>
> > write.table(x, file = "", append = FALSE, quote = TRUE, sep = " ",
> +             eol = "\n", na = "NA", dec = ".", row.names = TRUE,
> +             col.names = TRUE, qmethod = c("escape", "double"),
> +             fileEncoding = "")
> "area" "bedrooms" "sale.price"
>
> "9" 694 4 192
> "10" 905 4 215
> "11" 802 4 215
> "12" 1366 4 274
> "13" 716 4 112.7
> "14" 963 4 185
> "15" 821 4 212
> "16" 714 4 220
> "17" 1018 4 276
> "18" 887 4 260
> "19" 790 4 221.5
> "20" 696 5 255
> "21" 771 5 260
> "22" 1006 5 293
> "23" 1191 6 375
>
>
> --
> View this message in context:
> http://r.789695.n4.nabble.com/Using-write-table-i-have-a-table-with-two-columns-i-would-like-to-save-it-as-an-excel-file-tp3768829p3768829.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> [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.
>

        [[alternative HTML version deleted]]

______________________________________________
[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
|  
Report Content as Inappropriate
star

Re: Using write.table i have a table with two columns i would like to save it as an excel file

kevin123
Thank you for the help, csv works much better,

Kevin

On Thu, Aug 25, 2011 at 11:47 AM, R. Michael Weylandt <[hidden email]> [via R] <[hidden email]> wrote:
I'd suggest you should probably just use the simpler write.csv() function to
make a file type that will move much more conveniently between Excel and R.

The syntax is:

write.csv(ThingBeingSaved, "filename.csv")

If you only put the file name to write.csv it will be placed in your working
directory, which you can find by running getwd() at the command line. If you
put a whole path, R will put it there. If you want to change your working
directory, setwd() can do that.

As to what to name the file, well -- that's your problem, but it can be
basically anything you want as long as it ends in ".csv". (It doesn't even
technically have to do that, but please do -- it will make your life better
when dealing with Excel)

Michael

On Thu, Aug 25, 2011 at 12:58 PM, kevin123 <[hidden email]> wrote:

> Using write.table i would like to save data  as an excel file to a folder.
> I
> am not too sure how to write the file path or what to name the file. I
> would
> appreciate any feedback.
>
>
> > write.table(x, file = "", append = FALSE, quote = TRUE, sep = " ",
> +             eol = "\n", na = "NA", dec = ".", row.names = TRUE,
> +             col.names = TRUE, qmethod = c("escape", "double"),
> +             fileEncoding = "")
> "area" "bedrooms" "sale.price"
>
> "9" 694 4 192
> "10" 905 4 215
> "11" 802 4 215
> "12" 1366 4 274
> "13" 716 4 112.7
> "14" 963 4 185
> "15" 821 4 212
> "16" 714 4 220
> "17" 1018 4 276
> "18" 887 4 260
> "19" 790 4 221.5
> "20" 696 5 255
> "21" 771 5 260
> "22" 1006 5 293
> "23" 1191 6 375
>
>
> --
> View this message in context:
> http://r.789695.n4.nabble.com/Using-write-table-i-have-a-table-with-two-columns-i-would-like-to-save-it-as-an-excel-file-tp3768829p3768829.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> [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.
>

        [[alternative HTML version deleted]]

______________________________________________
[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.



To unsubscribe from Using write.table i have a table with two columns i would like to save it as an excel file, click here.

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: Using write.table i have a table with two columns i would like to save it as an excel file

Scott
This post was updated on .
In reply to this post by Michael Weylandt
One option you've got is to configure that your operating system so any CSV file will be opened up in Excel. Those instructions will depend on the type of operating system.

I'd usually turn row.names=FALSE on either write.table or write.csv as it's not that important (for what I do it's normally just consecutive numbers) but usually it's the default argument.

Depending on your operating system, and how Excel is set up, you might need write.csv2 - check out the manual page for write.table or write.csv for more details.        

>   ?write.table  

For the example you've shown, I'd turn off quotes - just because it's not that necessary when you have a separator as a comma. Those extra characters can really increase your file size which can be a problem if you work with large data.

If you end up using data where you might have entire sentences with commas, excel will likely space your data in a strange way because it think's that the sentence needs to be broken. Using a tab as the sep or using quote will get around this.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Odp: Using write.table i have a table with two columns i would like to save it as an excel file

PIKAL Petr
In reply to this post by kevin123
Hi

I use this kind of output to excel if the table is not too big

write.table(tab, "clipboard", sep = "\t", row.names = F)

In excel sheet I press ctrl - V to copy from clipboard

Regards
Petr
 
> Using write.table i would like to save data  as an excel file to a
folder. I
> am not too sure how to write the file path or what to name the file. I
would

> appreciate any feedback.
>
>
> > write.table(x, file = "", append = FALSE, quote = TRUE, sep = " ",
> +             eol = "\n", na = "NA", dec = ".", row.names = TRUE,
> +             col.names = TRUE, qmethod = c("escape", "double"),
> +             fileEncoding = "")
> "area" "bedrooms" "sale.price"
>
> "9" 694 4 192
> "10" 905 4 215
> "11" 802 4 215
> "12" 1366 4 274
> "13" 716 4 112.7
> "14" 963 4 185
> "15" 821 4 212
> "16" 714 4 220
> "17" 1018 4 276
> "18" 887 4 260
> "19" 790 4 221.5
> "20" 696 5 255
> "21" 771 5 260
> "22" 1006 5 293
> "23" 1191 6 375
>
>
> --
> View this message in context: http://r.789695.n4.nabble.com/Using-write-
>
table-i-have-a-table-with-two-columns-i-would-like-to-save-it-as-an-excel-
> file-tp3768829p3768829.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> [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.

______________________________________________
[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.
Loading...