Sally Ann Sims
2011-Oct-17 18:56 UTC
[R] Importing all observations and variables from csv file into dataframe
Hello, I need some help getting started with data analysis. I’m having trouble getting R to read my data file. I’ve referred to various R help documentation, the website, and FAQs, but I don’t see my situation listed. I saved an Excel file (post-2007 Excel version) of data as a “.csv” file. However, the file still appears in column format when I open it. Does that happen when you save a an Excel file in .csv format? I have used the function file.choose() to pull in the file into R. When I use the summary command I get: summary("C:\\Documents\\R_dfiles\\H_N_T.csv",header=TRUE,as.is=TRUE) Length Class Mode 1 character character But the data table actually has five columns and 1000 rows (example of first two lines): OBJECTID X Y elev HB_NHB 1 265712.1 90770.42 7.6372 0 When I look at the .csv file, I see that the OBJECTID cell is selected so I think R is just reading the one cell as my data. How can I get R to read the all the data rows and columns? Is there a way to clear the one-cell selection status? Or perhaps there is another issue that needs addressing. I would like to get this data table configured into R as a dataframe. Thank you, Sally [[alternative HTML version deleted]]
jim holtman
2011-Oct-17 19:09 UTC
[R] Importing all observations and variables from csv file into dataframe
I would assume that you would use 'read.csv'. I don't know where you got the syntax for "summary"; x <- read.csv(("C:\\Documents\\R_dfiles\\H_N_T.csv",as.is=TRUE) summary(x) On Mon, Oct 17, 2011 at 2:56 PM, Sally Ann Sims <sallysims at earthlink.net> wrote:> Hello, > > I need some help getting started with data analysis. ?I?m having trouble getting R to read my data file. ?I?ve referred to various R help documentation, the website, and FAQs, but I don?t see my situation listed. > > I saved an Excel file (post-2007 Excel version) of data as a ?.csv? file. ?However, the file still appears in column format when I open it. ?Does that happen when you save a an Excel file in .csv format? ?I have used the function file.choose() to pull in the file into R. ?When I use the summary command I get: > > summary("C:\\Documents\\R_dfiles\\H_N_T.csv",header=TRUE,as.is=TRUE) > ? Length ? ? Class ? ? ?Mode > ? ? ? ?1 character character > But the data table actually has five columns and 1000 rows (example of first two lines): > > ? ? ?OBJECTID X Y elev HB_NHB > ? ? ?1 265712.1 90770.42 7.6372 0 > > > When I look at the .csv file, I see that the OBJECTID cell is selected so I think R is just reading the one cell as my data. ?How can I get R to read the all the data rows and columns? ?Is there a way to clear the one-cell selection status? ?Or perhaps there is another issue that needs addressing. ?I would like to get this data table configured into R as a dataframe. > > Thank you, > Sally > ? ? ? ?[[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. > >-- Jim Holtman Data Munger Guru What is the problem that you are trying to solve?
R. Michael Weylandt
2011-Oct-17 19:09 UTC
[R] Importing all observations and variables from csv file into dataframe
You aren't reading the file in at all: notice that,> summary("MooGoesTheCow",header=TRUE,as.is=TRUE)Length Class Mode 1 character character This is because you are asking for a summary of the string containing the file name, not the file itself. Rather, use X = read.csv("C:\\Documents\\R_dfiles\\H_N_T.csv",header=TRUE,as.is=TRUE) and then start looking at X which will be an R object (data frame most likely) storing all the values of the spreadsheet. Hope this helps, Michael On Mon, Oct 17, 2011 at 2:56 PM, Sally Ann Sims <sallysims at earthlink.net> wrote:> Hello, > > I need some help getting started with data analysis. ?I?m having trouble getting R to read my data file. ?I?ve referred to various R help documentation, the website, and FAQs, but I don?t see my situation listed. > > I saved an Excel file (post-2007 Excel version) of data as a ?.csv? file. ?However, the file still appears in column format when I open it. ?Does that happen when you save a an Excel file in .csv format? ?I have used the function file.choose() to pull in the file into R. ?When I use the summary command I get: > > summary("C:\\Documents\\R_dfiles\\H_N_T.csv",header=TRUE,as.is=TRUE) > ? Length ? ? Class ? ? ?Mode > ? ? ? ?1 character character > But the data table actually has five columns and 1000 rows (example of first two lines): > > ? ? ?OBJECTID X Y elev HB_NHB > ? ? ?1 265712.1 90770.42 7.6372 0 > > > When I look at the .csv file, I see that the OBJECTID cell is selected so I think R is just reading the one cell as my data. ?How can I get R to read the all the data rows and columns? ?Is there a way to clear the one-cell selection status? ?Or perhaps there is another issue that needs addressing. ?I would like to get this data table configured into R as a dataframe. > > Thank you, > Sally > ? ? ? ?[[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. > >
Bert Gunter
2011-Oct-18 00:22 UTC
[R] Importing all observations and variables from csv file into dataframe
Oh please! Try reading the relevant docs -- like an Intro to R (The chapter on Reading data from files) or the R Data Import/Export manual. You will find plenty of help on this list, but you owe us an honest effort to help yourself first. -- Bert On Mon, Oct 17, 2011 at 11:56 AM, Sally Ann Sims <sallysims@earthlink.net>wrote:> Hello, > > I need some help getting started with data analysis. I’m having trouble > getting R to read my data file. I’ve referred to various R help > documentation, the website, and FAQs, but I don’t see my situation listed. > > I saved an Excel file (post-2007 Excel version) of data as a “.csv” file. > However, the file still appears in column format when I open it. Does that > happen when you save a an Excel file in .csv format? I have used the > function file.choose() to pull in the file into R. When I use the summary > command I get: > > summary("C:\\Documents\\R_dfiles\\H_N_T.csv",header=TRUE,as.is=TRUE) > Length Class Mode > 1 character character > But the data table actually has five columns and 1000 rows (example of > first two lines): > > OBJECTID X Y elev HB_NHB > 1 265712.1 90770.42 7.6372 0 > > > When I look at the .csv file, I see that the OBJECTID cell is selected so I > think R is just reading the one cell as my data. How can I get R to read > the all the data rows and columns? Is there a way to clear the one-cell > selection status? Or perhaps there is another issue that needs addressing. > I would like to get this data table configured into R as a dataframe. > > Thank you, > Sally > [[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. > >-- Bert Gunter Genentech Nonclinical Biostatistics Internal Contact Info: Phone: 467-7374 Website: http://pharmadevelopment.roche.com/index/pdb/pdb-functional-groups/pdb-biostatistics/pdb-ncb-home.htm [[alternative HTML version deleted]]