Hi R users, I have a problem in reading data. For example, part of my dataframe is like this: df month day year Discharge 3 1 2010 6.4 3 2 2010 7.58 3 3 2010 6.82 3 4 2010 8.63 3 5 2010 8.16 3 6 2010 7.58 Then if I type summary(df), why it converts the discharge data to levels? I also met the same problem when reading some other csv files. How to solve this problem? Thanks. Discharge 7.58 :2 6.4 :1 6.82 :1 8.63 :1 8.16 :1 [[alternative HTML version deleted]]
This indicates that your Discharge column has been stored/converted as a factor (run str(df) to verify and check other columns). This usually happens when functions like read.table are left to try to figure out what each column is and it finds something in that column that cannot be converted to a number (possibly an oh instead of a zero, an el instead of a one, or just a letter or punctuation mark accidentally in the file). You can either find the error in your original data, fix it, and reread the data, or specify that the column should be numeric using the colClasses argument to read.table or other function. On Tue, Sep 20, 2016 at 3:46 PM, lily li <chocold12 at gmail.com> wrote:> Hi R users, > > I have a problem in reading data. > For example, part of my dataframe is like this: > > df > month day year Discharge > 3 1 2010 6.4 > 3 2 2010 7.58 > 3 3 2010 6.82 > 3 4 2010 8.63 > 3 5 2010 8.16 > 3 6 2010 7.58 > > Then if I type summary(df), why it converts the discharge data to levels? I > also met the same problem when reading some other csv files. How to solve > this problem? Thanks. > > Discharge > 7.58 :2 > 6.4 :1 > 6.82 :1 > 8.63 :1 > 8.16 :1 > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > 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.-- Gregory (Greg) L. Snow Ph.D. 538280 at gmail.com
Yes, it is stored as factor. I can't check out any problem in the original data. Reread data doesn't help either. I use read.csv to read in the data, do you think it is better to use read.table? Thanks again. On Tue, Sep 20, 2016 at 3:55 PM, Greg Snow <538280 at gmail.com> wrote:> This indicates that your Discharge column has been stored/converted as > a factor (run str(df) to verify and check other columns). This > usually happens when functions like read.table are left to try to > figure out what each column is and it finds something in that column > that cannot be converted to a number (possibly an oh instead of a > zero, an el instead of a one, or just a letter or punctuation mark > accidentally in the file). You can either find the error in your > original data, fix it, and reread the data, or specify that the column > should be numeric using the colClasses argument to read.table or other > function. > > > > On Tue, Sep 20, 2016 at 3:46 PM, lily li <chocold12 at gmail.com> wrote: > > Hi R users, > > > > I have a problem in reading data. > > For example, part of my dataframe is like this: > > > > df > > month day year Discharge > > 3 1 2010 6.4 > > 3 2 2010 7.58 > > 3 3 2010 6.82 > > 3 4 2010 8.63 > > 3 5 2010 8.16 > > 3 6 2010 7.58 > > > > Then if I type summary(df), why it converts the discharge data to > levels? I > > also met the same problem when reading some other csv files. How to solve > > this problem? Thanks. > > > > Discharge > > 7.58 :2 > > 6.4 :1 > > 6.82 :1 > > 8.63 :1 > > 8.16 :1 > > > > [[alternative HTML version deleted]] > > > > ______________________________________________ > > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > > 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. > > > > -- > Gregory (Greg) L. Snow Ph.D. > 538280 at gmail.com >[[alternative HTML version deleted]]