Exporting column names with spaces with write.csv() XXXX

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

Exporting column names with spaces with write.csv() XXXX

Dan Abner
Hi all,

I have a number of columns with spaces in the column names exactly as
I want them in R. When I go to export the data table to csv using
write.csv(), the fn adds periods in place of the spaces.

Is there a way to suppress the addition of the periods?

Thanks,

Dan

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
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: Exporting column names with spaces with write.csv() XXXX

Jeff Newmiller
Reproducible example, please.
---------------------------------------------------------------------------
Jeff Newmiller                        The     .....       .....  Go Live...
DCN:<[hidden email]>        Basics: ##.#.       ##.#.  Live Go...
                                      Live:   OO#.. Dead: OO#..  Playing
Research Engineer (Solar/Batteries            O.O#.       #.O#.  with
/Software/Embedded Controllers)               .OO#.       .OO#.  rocks...1k
---------------------------------------------------------------------------
Sent from my phone. Please excuse my brevity.

On September 5, 2015 7:09:28 PM PDT, Dan Abner <[hidden email]> wrote:

>Hi all,
>
>I have a number of columns with spaces in the column names exactly as
>I want them in R. When I go to export the data table to csv using
>write.csv(), the fn adds periods in place of the spaces.
>
>Is there a way to suppress the addition of the periods?
>
>Thanks,
>
>Dan
>
>______________________________________________
>[hidden email] mailing list -- To UNSUBSCRIBE and more, see
>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 -- To UNSUBSCRIBE and more, see
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: Exporting column names with spaces with write.csv() XXXX

Jim Lemon-4
In reply to this post by Dan Abner
Hi Dan,
I don't get this behavior with R-3.2.2:

da.df<-data.frame(1:3,4:6)
names(da.df)<-c("no good","no good at all")
> da.df
  no good no good at all
1       1              4
2       2              5
3       3              6
write.csv(da.df,file="gloop.csv",row.names=FALSE)

gives me this:

"no good","no good at all"
1,4
2,5
3,6

Are you sure that R didn't add the periods when you created the data frame?
They would then be written into the CSV file.

Jim



On Sun, Sep 6, 2015 at 12:09 PM, Dan Abner <[hidden email]> wrote:

> Hi all,
>
> I have a number of columns with spaces in the column names exactly as
> I want them in R. When I go to export the data table to csv using
> write.csv(), the fn adds periods in place of the spaces.
>
> Is there a way to suppress the addition of the periods?
>
> Thanks,
>
> Dan
>
> ______________________________________________
> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
> 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 -- To UNSUBSCRIBE and more, see
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: Exporting column names with spaces with write.csv() XXXX

djmuseR
...or, when trying to read it back into R,

read.csv(header = TRUE, text = '
"no good","no good at all"
1,4
2,5
3,6')

  no.good no.good.at.all
1       1              4
2       2              5
3       3              6


read.csv(header = TRUE, check.names = FALSE, text = '
"no good","no good at all"
1,4
2,5
3,6')

  no good no good at all
1       1              4
2       2              5
3       3              6


Thanks for the MWE, Jim.

Dennis

On Sat, Sep 5, 2015 at 7:57 PM, Jim Lemon <[hidden email]> wrote:

> Hi Dan,
> I don't get this behavior with R-3.2.2:
>
> da.df<-data.frame(1:3,4:6)
> names(da.df)<-c("no good","no good at all")
>> da.df
>   no good no good at all
> 1       1              4
> 2       2              5
> 3       3              6
> write.csv(da.df,file="gloop.csv",row.names=FALSE)
>
> gives me this:
>
> "no good","no good at all"
> 1,4
> 2,5
> 3,6
>
> Are you sure that R didn't add the periods when you created the data frame?
> They would then be written into the CSV file.
>
> Jim
>
>
>
> On Sun, Sep 6, 2015 at 12:09 PM, Dan Abner <[hidden email]> wrote:
>
>> Hi all,
>>
>> I have a number of columns with spaces in the column names exactly as
>> I want them in R. When I go to export the data table to csv using
>> write.csv(), the fn adds periods in place of the spaces.
>>
>> Is there a way to suppress the addition of the periods?
>>
>> Thanks,
>>
>> Dan
>>
>> ______________________________________________
>> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
>> 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 -- To UNSUBSCRIBE and more, see
> 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 -- To UNSUBSCRIBE and more, see
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.