Re: [R] Importing CSV File
Hi r-help-boun...@r-project.org 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: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On > Behalf Of Jason Kwok > Sent: Monday, 25 October 2010 8:27 AM > To: Erik Iverson > Cc: r-help@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? 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 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 > >> 1January 422 > >> 2 February 151 > >> 3 March 451 > >> 4 April 175 > >> 5May 131 > >> 6 June 307 > >> 7 July47 > >> 8 August12 > >> 9 September 488 > >> 10 October 122 > >> 11 November54 > >> 12 December 244 > >> > >>> * > >>> > >> > >>[[alternative HTML version deleted]] > >> > >> __ > >> R-help@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]] > > __ > R-help@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. __ R-help@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.
Re: [R] Importing CSV File
On Mon, Oct 25, 2010 at 12:26 AM, Jason Kwok 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 __ R-help@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.
Re: [R] Importing CSV File
sales <- read.csv(file="C:/Program Files/R/Test Data/sales.csv", header=TRUE, row.names = "Month") ^^^ -Original Message- From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On Behalf Of Jason Kwok Sent: Monday, 25 October 2010 8:27 AM To: Erik Iverson Cc: r-help@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 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 >> 1January 422 >> 2 February 151 >> 3 March 451 >> 4 April 175 >> 5May 131 >> 6 June 307 >> 7 July47 >> 8 August12 >> 9 September 488 >> 10 October 122 >> 11 November54 >> 12 December 244 >> >>> * >>> >> >>[[alternative HTML version deleted]] >> >> __ >> R-help@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]] __ R-help@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.
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 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 >> 1January 422 >> 2 February 151 >> 3 March 451 >> 4 April 175 >> 5May 131 >> 6 June 307 >> 7 July47 >> 8 August12 >> 9 September 488 >> 10 October 122 >> 11 November54 >> 12 December 244 >> >>> * >>> >> >>[[alternative HTML version deleted]] >> >> __ >> R-help@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]] __ R-help@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.
Re: [R] Importing CSV File
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 1January 422 2 February 151 3 March 451 4 April 175 5May 131 6 June 307 7 July47 8 August12 9 September 488 10 October 122 11 November54 12 December 244 * [[alternative HTML version deleted]] __ R-help@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. __ R-help@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.
[R] Importing CSV File
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 1January 422 2 February 151 3 March 451 4 April 175 5May 131 6 June 307 7 July47 8 August12 9 September 488 10 October 122 11 November54 12 December 244 > * [[alternative HTML version deleted]] __ R-help@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.
Re: [R] Importing csv file with character values into sqlite3 and subsequent problem in R / RSQLite
There are some examples of reading files into sqlite on the sqldf home page: http://sqldf.googlecode.com On Mon, Mar 30, 2009 at 12:19 PM, Stephan Lindner wrote: > Dear all, > > > I'm trying to import a csv file into sqlite3 and from there into > R. Everything looks fine exepct that R outputs the character values in > an odd fashion: they are shown as "\"CHARACTER\"" instead of > "CHARACTER", but only if I show the character variable as a > vector. Does someone know why this happens? Below is a sample > code. The first part is written in bash. Of course I could just > read.csv for the spreadsheet, but the real datasets are more than 3 > GB, that's why I'm using RSQLite (which is really awesome!). Also, I > could get rid of the "" in the csv file (the csv file has only > numbers, but it is easier for my to use identifiers such as v1 as > character strings), but I thought I'd first see whether there is a > different way to solve this issue. > > > Thanks! > > > Stephan > > > <-- > > bash$ more example.csv > bash$ echo -e > "\"001074034\",90,1,7,89,12\n\"001074034\",90,1,1,90,12\n\"001074034\",90,1,2,90,12\n\"001074034\",90,1,3,90,12" > > example.csv > bash$ echo "create table t(v1,v2,v3,v4,v5,v6);" > example.sql > bash$ sqlite3 example.db < example.sql > bash$ echo -e ".separator , \n.import example.csv t" | sqlite3 example.db > bash$ R >> library(RSQLite) > Loading required package: DBI >> example.db <- dbConnect(SQLite(),"example.db") >> x <- dbGetQuery(example.db,"select * from t") >> x > v1 v2 v3 v4 v5 v6 > 1 "001074034" 90 1 7 89 12 > 2 "001074034" 90 1 1 90 12 > 3 "001074034" 90 1 2 90 12 > 4 "001074034" 90 1 3 90 12 > >> x$v1 > [1] "\"001074034\"" "\"001074034\"" "\"001074034\"" "\"001074034\"" > > --> > > > Only the codes: > > > <-- > > more example.csv > echo -e > "\"001074034\",90,1,7,89,12\n\"001074034\",90,1,1,90,12\n\"001074034\",90,1,2,90,12\n\"001074034\",90,1,3,90,12" > > example.csv > echo "create table t(v1,v2,v3,v4,v5,v6);" > example.sql > sqlite3 example.db < example.sql > echo -e ".separator , \n.import example.csv t" | sqlite3 example.db > R > > library(RSQLite) > example.db <- dbConnect(SQLite(),"example.db") > x <- dbGetQuery(example.db,"select * from t") > x > x$v1 > > --> > > > > > -- > --- > Stephan Lindner > University of Michigan > > __ > R-help@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. > __ R-help@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.
[R] Importing csv file with character values into sqlite3 and subsequent problem in R / RSQLite
Dear all, I'm trying to import a csv file into sqlite3 and from there into R. Everything looks fine exepct that R outputs the character values in an odd fashion: they are shown as "\"CHARACTER\"" instead of "CHARACTER", but only if I show the character variable as a vector. Does someone know why this happens? Below is a sample code. The first part is written in bash. Of course I could just read.csv for the spreadsheet, but the real datasets are more than 3 GB, that's why I'm using RSQLite (which is really awesome!). Also, I could get rid of the "" in the csv file (the csv file has only numbers, but it is easier for my to use identifiers such as v1 as character strings), but I thought I'd first see whether there is a different way to solve this issue. Thanks! Stephan <-- bash$ more example.csv bash$ echo -e "\"001074034\",90,1,7,89,12\n\"001074034\",90,1,1,90,12\n\"001074034\",90,1,2,90,12\n\"001074034\",90,1,3,90,12" > example.csv bash$ echo "create table t(v1,v2,v3,v4,v5,v6);" > example.sql bash$ sqlite3 example.db < example.sql bash$ echo -e ".separator , \n.import example.csv t" | sqlite3 example.db bash$ R > library(RSQLite) Loading required package: DBI > example.db <- dbConnect(SQLite(),"example.db") > x <- dbGetQuery(example.db,"select * from t") > x v1 v2 v3 v4 v5 v6 1 "001074034" 90 1 7 89 12 2 "001074034" 90 1 1 90 12 3 "001074034" 90 1 2 90 12 4 "001074034" 90 1 3 90 12 > x$v1 [1] "\"001074034\"" "\"001074034\"" "\"001074034\"" "\"001074034\"" --> Only the codes: <-- more example.csv echo -e "\"001074034\",90,1,7,89,12\n\"001074034\",90,1,1,90,12\n\"001074034\",90,1,2,90,12\n\"001074034\",90,1,3,90,12" > example.csv echo "create table t(v1,v2,v3,v4,v5,v6);" > example.sql sqlite3 example.db < example.sql echo -e ".separator , \n.import example.csv t" | sqlite3 example.db R library(RSQLite) example.db <- dbConnect(SQLite(),"example.db") x <- dbGetQuery(example.db,"select * from t") x x$v1 --> -- --- Stephan Lindner University of Michigan __ R-help@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.