[R] Importing CSV File

Bill.Venables at csiro.au Bill.Venables at csiro.au
Mon Oct 25 00:47:22 CEST 2010


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


-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of Jason Kwok
Sent: Monday, 25 October 2010 8:27 AM
To: Erik Iverson
Cc: r-help at r-project.org
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 <eriki at ccbr.umn.edu> 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]]
>>
>> ______________________________________________
>> 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.
>>
>
>

	[[alternative HTML version deleted]]



More information about the R-help mailing list