import .csv file into R

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

import .csv file into R

Marion Wenty
Dear r-helpers,

I read  a .csv file into R

with the following command:

A<-read.csv2(file="Mappe3.csv")

It worked fine, except that I would like to get rid of the points between
the words and get spaces instead like I have got in the .csv file.

At the moment it looks like the following:

habe.mich.gut.mit.KlassenkollegInnen.verstanden
hatte.gutes.Verhältnis.zu.Eltern
fühlte.mich.von.LehrerInnen.respektiert
1                                              88
         86                                      74
  fühlte.mich.von.LehrerInnen.ausreichend.gefördert
Eltern.konnten.mir.beim.Lernen.helfen
1                                                62
                41


So far I couldn't find out how to do this. Could anyone help me with this?


Many Thanks in advance!


Marion

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

Re: import .csv file into R

Michael Weylandt
check.names=FALSE

but it's discouraged because it will make it hard to refer to column
names inside R.

Michael

On Thu, Feb 16, 2012 at 11:18 AM, Marion Wenty <[hidden email]> wrote:

> Dear r-helpers,
>
> I read  a .csv file into R
>
> with the following command:
>
> A<-read.csv2(file="Mappe3.csv")
>
> It worked fine, except that I would like to get rid of the points between
> the words and get spaces instead like I have got in the .csv file.
>
> At the moment it looks like the following:
>
> habe.mich.gut.mit.KlassenkollegInnen.verstanden
> hatte.gutes.Verhältnis.zu.Eltern
> fühlte.mich.von.LehrerInnen.respektiert
> 1                                              88
>         86                                      74
>  fühlte.mich.von.LehrerInnen.ausreichend.gefördert
> Eltern.konnten.mir.beim.Lernen.helfen
> 1                                                62
>                41
>
>
> So far I couldn't find out how to do this. Could anyone help me with this?
>
>
> Many Thanks in advance!
>
>
> Marion
>
>        [[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.
>

______________________________________________
[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: import .csv file into R

Rui Barradas
In reply to this post by Marion Wenty
Hello,

> I read  a .csv file into R
>
> with the following command:
>
> A<-read.csv2(file="Mappe3.csv")
>
> It worked fine, except that I would like to get rid of the points between
> the words and get spaces instead like I have got in the .csv file.

Try

gsub('\\.', ' ', A)

(And see ?regexpr and ?gsub)

Rui Barradas
Reply | Threaded
Open this post in threaded view
|

Re: import .csv file into R

Marion Wenty
In reply to this post by Michael Weylandt
David, thanks for the tips, though, I tried these arguments but it didn'
work.

Michael, thanks for your advice which worked, so far. I am using my object
to create a barplot afterwards, which automatically puts the colnames
besides the bars. Maybe this is still a good solution for my purpose as I
don't need to work with the colnames afterwards?

Thanks a lot!

Marion


Versuch es mal mit den Argumenten sep=";"  (oder das jeweilige Zeichen, das
deine Felder abtrennt)
und dec='.'  (oder ein anderes Zeichen für deine Kommastellen)

Gruss

2012/2/16 R. Michael Weylandt <[hidden email]>

> check.names=FALSE
>
> but it's discouraged because it will make it hard to refer to column
> names inside R.
>
> Michael
>
> On Thu, Feb 16, 2012 at 11:18 AM, Marion Wenty <[hidden email]>
> wrote:
> > Dear r-helpers,
> >
> > I read  a .csv file into R
> >
> > with the following command:
> >
> > A<-read.csv2(file="Mappe3.csv")
> >
> > It worked fine, except that I would like to get rid of the points between
> > the words and get spaces instead like I have got in the .csv file.
> >
> > At the moment it looks like the following:
> >
> > habe.mich.gut.mit.KlassenkollegInnen.verstanden
> > hatte.gutes.Verhältnis.zu.Eltern
> > fühlte.mich.von.LehrerInnen.respektiert
> > 1                                              88
> >         86                                      74
> >  fühlte.mich.von.LehrerInnen.ausreichend.gefördert
> > Eltern.konnten.mir.beim.Lernen.helfen
> > 1                                                62
> >                41
> >
> >
> > So far I couldn't find out how to do this. Could anyone help me with
> this?
> >
> >
> > Many Thanks in advance!
> >
> >
> > Marion
> >
> >        [[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.
> >
>
        [[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
|

Re: import .csv file into R

Michael Weylandt
If you don't need to refer to colnames you should be fine.

If you do need to subset by colnames, you can still do it with `[`,
but you'll have trouble if you want to use the $ trick, unless you use
back-ticks. Don't worry about these things if they aren't troubling
you now though.

Michael

On Thu, Feb 16, 2012 at 11:48 AM, Marion Wenty <[hidden email]> wrote:

> David, thanks for the tips, though, I tried these arguments but it didn'
> work.
>
> Michael, thanks for your advice which worked, so far. I am using my object
> to create a barplot afterwards, which automatically puts the colnames
> besides the bars. Maybe this is still a good solution for my purpose as I
> don't need to work with the colnames afterwards?
>
> Thanks a lot!
>
> Marion
>
>
> Versuch es mal mit den Argumenten sep=";"  (oder das jeweilige Zeichen, das
> deine Felder abtrennt)
> und dec='.'  (oder ein anderes Zeichen für deine Kommastellen)
>
> Gruss
>
> 2012/2/16 R. Michael Weylandt <[hidden email]>
>>
>> check.names=FALSE
>>
>> but it's discouraged because it will make it hard to refer to column
>> names inside R.
>>
>> Michael
>>
>> On Thu, Feb 16, 2012 at 11:18 AM, Marion Wenty <[hidden email]>
>> wrote:
>> > Dear r-helpers,
>> >
>> > I read  a .csv file into R
>> >
>> > with the following command:
>> >
>> > A<-read.csv2(file="Mappe3.csv")
>> >
>> > It worked fine, except that I would like to get rid of the points
>> > between
>> > the words and get spaces instead like I have got in the .csv file.
>> >
>> > At the moment it looks like the following:
>> >
>> > habe.mich.gut.mit.KlassenkollegInnen.verstanden
>> > hatte.gutes.Verhältnis.zu.Eltern
>> > fühlte.mich.von.LehrerInnen.respektiert
>> > 1                                              88
>> >         86                                      74
>> >  fühlte.mich.von.LehrerInnen.ausreichend.gefördert
>> > Eltern.konnten.mir.beim.Lernen.helfen
>> > 1                                                62
>> >                41
>> >
>> >
>> > So far I couldn't find out how to do this. Could anyone help me with
>> > this?
>> >
>> >
>> > Many Thanks in advance!
>> >
>> >
>> > Marion
>> >
>> >        [[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.
>> >
>
>

______________________________________________
[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: import .csv file into R

Marion Wenty
In reply to this post by Rui Barradas
Hi Michael and Rui,

thanks a lot for the tips.

It worked with both your suggestions!

I also found out, that this problem only exists if I put header=T.

Thanks again!

Marion


If you don't need to refer to colnames you should be fine.

If you do need to subset by colnames, you can still do it with `[`,
but you'll have trouble if you want to use the $ trick, unless you use
back-ticks. Don't worry about these things if they aren't troubling
you now though.

Michael

2012/2/16 Rui Barradas <[hidden email]>

> Hello,
>
> > I read  a .csv file into R
> >
> > with the following command:
> >
> > A<-read.csv2(file="Mappe3.csv")
> >
> > It worked fine, except that I would like to get rid of the points between
> > the words and get spaces instead like I have got in the .csv file.
>
> Try
>
> gsub('\\.', ' ', A)
>
> (And see ?regexpr and ?gsub)
>
> Rui Barradas
>
>
> --
> View this message in context:
> http://r.789695.n4.nabble.com/import-csv-file-into-R-tp4394533p4394573.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
|

Re: import .csv file into R

Marion Wenty
Hi Michael,
thanks a lot for the additional tips! So far it all has worked!
Marion

2012/2/17 Marion Wenty <[hidden email]>

> Hi Michael and Rui,
>
> thanks a lot for the tips.
>
> It worked with both your suggestions!
>
> I also found out, that this problem only exists if I put header=T.
>
> Thanks again!
>
> Marion
>
>
> If you don't need to refer to colnames you should be fine.
>
> If you do need to subset by colnames, you can still do it with `[`,
> but you'll have trouble if you want to use the $ trick, unless you use
> back-ticks. Don't worry about these things if they aren't troubling
> you now though.
>
> Michael
>
> 2012/2/16 Rui Barradas <[hidden email]>
>
>> Hello,
>>
>> > I read  a .csv file into R
>> >
>> > with the following command:
>> >
>> > A<-read.csv2(file="Mappe3.csv")
>> >
>> > It worked fine, except that I would like to get rid of the points
>> between
>> > the words and get spaces instead like I have got in the .csv file.
>>
>> Try
>>
>> gsub('\\.', ' ', A)
>>
>> (And see ?regexpr and ?gsub)
>>
>> Rui Barradas
>>
>>
>> --
>> View this message in context:
>> http://r.789695.n4.nabble.com/import-csv-file-into-R-tp4394533p4394573.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.