Quantcast

Importing CSV File

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

Importing CSV File

Jason Kwok
I'm trying to import a CSV file into R and when it gets imported, the
entries get numbered down the left side.  How do I get rid of that?

Thanks,

Jason

*> read.csv(file="C:\\Program Files\\R\\Test Data\\sales.csv",head=TRUE)
       Month Sales
1    January   422
2   February   151
3      March   451
4      April   175
5        May   131
6       June   307
7       July    47
8     August    12
9  September   488
10   October   122
11  November    54
12  December   244
> *

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

Re: Importing CSV File

Erik Iverson-3
On 10/24/2010 04:57 PM, Jason Kwok wrote:
> I'm trying to import a CSV file into R and when it gets imported, the
> entries get numbered down the left side.  How do I get rid of that?

When you imported the CSV file into R, an object of class data.frame
was created, and since you did not assign it to a variable name,
(e.g., df1 <- read.csv(...) ), the object got printed.

A data.frame object is going to have a row.names attribute by definition,
which is what you're seeing.

In ?data.frame, we see documentation for the "row.names" argument:

  If ‘row.names’ was supplied as ‘NULL’
      or no suitable component was found the row names are the integer
      sequence starting at one (and such row names are considered to be
      ‘automatic’, and not preserved by ‘as.matrix’).

The method that prints out a data.frame is called print.data.frame,
and it does have an argument to suppress printing of the row.names.

The question is, why do you not want row.names?  Are they just
distracting you when printed, or is there some reason not to
carry them along in the object?

--Erik


>
> Thanks,
>
> Jason
>
> *>  read.csv(file="C:\\Program Files\\R\\Test Data\\sales.csv",head=TRUE)
>         Month Sales
> 1    January   422
> 2   February   151
> 3      March   451
> 4      April   175
> 5        May   131
> 6       June   307
> 7       July    47
> 8     August    12
> 9  September   488
> 10   October   122
> 11  November    54
> 12  December   244
>> *
>
> [[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
|  
Report Content as Inappropriate

Re: Importing CSV File

Jason Kwok
Thanks for the response Erik.

In this case, I would like to keep the row name as the month.  How would I
do that?

Thanks,

Jason

On Sun, Oct 24, 2010 at 6:20 PM, Erik Iverson <[hidden email]> wrote:

> On 10/24/2010 04:57 PM, Jason Kwok wrote:
>
>> I'm trying to import a CSV file into R and when it gets imported, the
>> entries get numbered down the left side.  How do I get rid of that?
>>
>
> When you imported the CSV file into R, an object of class data.frame
> was created, and since you did not assign it to a variable name,
> (e.g., df1 <- read.csv(...) ), the object got printed.
>
> A data.frame object is going to have a row.names attribute by definition,
> which is what you're seeing.
>
> In ?data.frame, we see documentation for the "row.names" argument:
>
>  If ‘row.names’ was supplied as ‘NULL’
>     or no suitable component was found the row names are the integer
>     sequence starting at one (and such row names are considered to be
>     ‘automatic’, and not preserved by ‘as.matrix’).
>
> The method that prints out a data.frame is called print.data.frame,
> and it does have an argument to suppress printing of the row.names.
>
> The question is, why do you not want row.names?  Are they just
> distracting you when printed, or is there some reason not to
> carry them along in the object?
>
> --Erik
>
>
>
>> Thanks,
>>
>> Jason
>>
>> *>  read.csv(file="C:\\Program Files\\R\\Test Data\\sales.csv",head=TRUE)
>>        Month Sales
>> 1    January   422
>> 2   February   151
>> 3      March   451
>> 4      April   175
>> 5        May   131
>> 6       June   307
>> 7       July    47
>> 8     August    12
>> 9  September   488
>> 10   October   122
>> 11  November    54
>> 12  December   244
>>
>>> *
>>>
>>
>>        [[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
|  
Report Content as Inappropriate

Re: Importing CSV File

Bill.Venables
sales <- read.csv(file="C:/Program Files/R/Test Data/sales.csv",
                                header=TRUE, row.names = "Month")
________________________________^^^^^^^^^^^^^^^^^^^


-----Original Message-----
From: [hidden email] [mailto:[hidden email]] On Behalf Of Jason Kwok
Sent: Monday, 25 October 2010 8:27 AM
To: Erik Iverson
Cc: [hidden email]
Subject: Re: [R] Importing CSV File

Thanks for the response Erik.

In this case, I would like to keep the row name as the month.  How would I
do that?

Thanks,

Jason

On Sun, Oct 24, 2010 at 6:20 PM, Erik Iverson <[hidden email]> wrote:

> On 10/24/2010 04:57 PM, Jason Kwok wrote:
>
>> I'm trying to import a CSV file into R and when it gets imported, the
>> entries get numbered down the left side.  How do I get rid of that?
>>
>
> When you imported the CSV file into R, an object of class data.frame
> was created, and since you did not assign it to a variable name,
> (e.g., df1 <- read.csv(...) ), the object got printed.
>
> A data.frame object is going to have a row.names attribute by definition,
> which is what you're seeing.
>
> In ?data.frame, we see documentation for the "row.names" argument:
>
>  If 'row.names' was supplied as 'NULL'
>     or no suitable component was found the row names are the integer
>     sequence starting at one (and such row names are considered to be
>     'automatic', and not preserved by 'as.matrix').
>
> The method that prints out a data.frame is called print.data.frame,
> and it does have an argument to suppress printing of the row.names.
>
> The question is, why do you not want row.names?  Are they just
> distracting you when printed, or is there some reason not to
> carry them along in the object?
>
> --Erik
>
>
>
>> Thanks,
>>
>> Jason
>>
>> *>  read.csv(file="C:\\Program Files\\R\\Test Data\\sales.csv",head=TRUE)
>>        Month Sales
>> 1    January   422
>> 2   February   151
>> 3      March   451
>> 4      April   175
>> 5        May   131
>> 6       June   307
>> 7       July    47
>> 8     August    12
>> 9  September   488
>> 10   October   122
>> 11  November    54
>> 12  December   244
>>
>>> *
>>>
>>
>>        [[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
|  
Report Content as Inappropriate

Re: Importing CSV File

Liviu Andronic
In reply to this post by Jason Kwok
On Mon, Oct 25, 2010 at 12:26 AM, Jason Kwok <[hidden email]> wrote:
> Thanks for the response Erik.
>
> In this case, I would like to keep the row name as the month.  How would I
> do that?
>
You can do this in Rcmdr. First Data > Import > From text file (or
select your data.frame as active data set), then Data > Active data
set > Set case names. Rcmdr will display the R code used to perform
the two operations. Regards
Liviu

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

Re: Importing CSV File

PIKAL Petr
In reply to this post by Bill.Venables
Hi

[hidden email] napsal dne 25.10.2010 00:47:22:

> sales <- read.csv(file="C:/Program Files/R/Test Data/sales.csv",
>             header=TRUE, row.names = "Month")
> ________________________________^^^^^^^^^^^^^^^^^^^
>
>
> -----Original Message-----
> From: [hidden email] [mailto:[hidden email]]
On
> Behalf Of Jason Kwok
> Sent: Monday, 25 October 2010 8:27 AM
> To: Erik Iverson
> Cc: [hidden email]
> Subject: Re: [R] Importing CSV File
>
> Thanks for the response Erik.
>
> In this case, I would like to keep the row name as the month.  How would
I
> do that?

Following Bill's answer I would add that you can not have duplicated row
names. In your example it does not matter as each month is unique, but if
you have more occurrences of some months you can not use it as a row name.

Regards
Petr

>
> Thanks,
>
> Jason
>
> On Sun, Oct 24, 2010 at 6:20 PM, Erik Iverson <[hidden email]>
wrote:

>
> > On 10/24/2010 04:57 PM, Jason Kwok wrote:
> >
> >> I'm trying to import a CSV file into R and when it gets imported, the
> >> entries get numbered down the left side.  How do I get rid of that?
> >>
> >
> > When you imported the CSV file into R, an object of class data.frame
> > was created, and since you did not assign it to a variable name,
> > (e.g., df1 <- read.csv(...) ), the object got printed.
> >
> > A data.frame object is going to have a row.names attribute by
definition,

> > which is what you're seeing.
> >
> > In ?data.frame, we see documentation for the "row.names" argument:
> >
> >  If 'row.names' was supplied as 'NULL'
> >     or no suitable component was found the row names are the integer
> >     sequence starting at one (and such row names are considered to be
> >     'automatic', and not preserved by 'as.matrix').
> >
> > The method that prints out a data.frame is called print.data.frame,
> > and it does have an argument to suppress printing of the row.names.
> >
> > The question is, why do you not want row.names?  Are they just
> > distracting you when printed, or is there some reason not to
> > carry them along in the object?
> >
> > --Erik
> >
> >
> >
> >> Thanks,
> >>
> >> Jason
> >>
> >> *>  read.csv(file="C:\\Program Files\\R\\Test
Data\\sales.csv",head=TRUE)

> >>        Month Sales
> >> 1    January   422
> >> 2   February   151
> >> 3      March   451
> >> 4      April   175
> >> 5        May   131
> >> 6       June   307
> >> 7       July    47
> >> 8     August    12
> >> 9  September   488
> >> 10   October   122
> >> 11  November    54
> >> 12  December   244
> >>
> >>> *
> >>>
> >>
> >>        [[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.

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