Hi list I loaded the content of a file dureetasks.txt to variable a. This file contains an interger per line. when I print a vector, it displays correctly. however, when I try to print the histogram, I get this error message> a=read.table("dureetasks.txt") > hist(a)Error in hist.default(a) : 'x' must be numeric Can you help please? regards -- PhD candidate in Computer Science Address 3 avenue lamine, cité ezzahra, Sousse 4000 Tunisia tel: +216 97 246 706 (+33640302046 jusqu'au 15/6) fax: +216 71 391 166 [[alternative HTML version deleted]]
On Sat, 2010-08-21 at 11:37 +0200, Adel ESSAFI wrote:> Hi list > > I loaded the content of a file dureetasks.txt to variable a. This file > contains an interger per line. > when I print a vector, it displays correctly. > however, when I try to print the histogram, I get this error message > > > a=read.table("dureetasks.txt") > > hist(a) > Error in hist.default(a) : 'x' must be numeric > > Can you help please?class(a) str(a)> a <- data.frame(x = rnorm(100)) > hist(a)Error in hist.default(a) : 'x' must be numeric So I suspect a is a data frame with a single column/variable. You need to pass hist the vector from /inside/ a that you want to plot:> with(a, hist(x))is one way to do that. Note that 'x' is used because that is the name of the variable (component really) in a that I want to plot:> names(a)[1] "x" You will need to work out what the correct name is for the component you want to plot. If there was no header to your text file then IIRC the variable will be named X1, but run names(a) and see what it returns. Because we don't have your dureetasks.txt file, there is no way for me to clarify that this is the problem and nothing else. If you can't send us data at the very least use tools like str(a) and class(a), and head(a) to show us what the data look like. HTH G> > regards > > > > > ______________________________________________ > 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.-- %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% Dr. Gavin Simpson [t] +44 (0)20 7679 0522 ECRC, UCL Geography, [f] +44 (0)20 7679 0565 Pearson Building, [e] gavin.simpsonATNOSPAMucl.ac.uk Gower Street, London [w] http://www.ucl.ac.uk/~ucfagls/ UK. WC1E 6BT. [w] http://www.freshwaters.org.uk %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
---------- Forwarded message ---------- From: Adel ESSAFI <adelessafi@gmail.com> Date: 2010/8/21 Subject: Re: [R] basic hist() question To: Henrique Dallazuanna <wwwhsd@gmail.com> It works fine. Could you explain to me why it did not worked for read.table? regards Adel 2010/8/21 Henrique Dallazuanna <wwwhsd@gmail.com>> Try this: > > a <- scan('dureetasks.txt') > hist(a) > > On Sat, Aug 21, 2010 at 10:32 AM, Adel ESSAFI <adelessafi@gmail.com>wrote: > >> Hi >> In fact, I searching for a simpler solution. I remember that I have done >> this without these functions (but I forgot) >> simply, is there any function that "force" R to take variable a as table >> ? >> >> Regards >> Adel >> >> >> >> > a=read.table("dureetasks.txt") >> > summary(a) >> V1 >> Min. : 1 >> 1st Qu.: 77 >> Median : 2658 >> Mean : 25802 >> 3rd Qu.: 42558 >> Max. :1575814 >> > hist(a); >> Error in hist.default(a) : 'x' must be numeric >> >> >> >> 2010/8/21 Gavin Simpson <gavin.simpson@ucl.ac.uk> >> >> > On Sat, 2010-08-21 at 11:37 +0200, Adel ESSAFI wrote: >> > > Hi list >> > > >> > > I loaded the content of a file dureetasks.txt to variable a. This >> file >> > > contains an interger per line. >> > > when I print a vector, it displays correctly. >> > > however, when I try to print the histogram, I get this error message >> > > >> > > > a=read.table("dureetasks.txt") >> > > > hist(a) >> > > Error in hist.default(a) : 'x' must be numeric >> > > >> > > Can you help please? >> > >> > class(a) >> > >> > str(a) >> > >> > > a <- data.frame(x = rnorm(100)) >> > > hist(a) >> > Error in hist.default(a) : 'x' must be numeric >> > >> > So I suspect a is a data frame with a single column/variable. You need >> > to pass hist the vector from /inside/ a that you want to plot: >> > >> > > with(a, hist(x)) >> > >> > is one way to do that. Note that 'x' is used because that is the name of >> > the variable (component really) in a that I want to plot: >> > >> > > names(a) >> > [1] "x" >> > >> > You will need to work out what the correct name is for the component you >> > want to plot. If there was no header to your text file then IIRC the >> > variable will be named X1, but run names(a) and see what it returns. >> > >> > Because we don't have your dureetasks.txt file, there is no way for me >> > to clarify that this is the problem and nothing else. If you can't send >> > us data at the very least use tools like str(a) and class(a), and >> > head(a) to show us what the data look like. >> > >> > HTH >> > >> > G >> > >> > > >> > > regards >> > > >> > > >> > > >> > > >> > > ______________________________________________ >> > > 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. >> > >> > -- >> > %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% >> > Dr. Gavin Simpson [t] +44 (0)20 7679 0522 >> > ECRC, UCL Geography, [f] +44 (0)20 7679 0565 >> > Pearson Building, [e] gavin.simpsonATNOSPAMucl.ac.uk >> > Gower Street, London [w] http://www.ucl.ac.uk/~ucfagls/<http://www.ucl.ac.uk/%7Eucfagls/> >> <http://www.ucl.ac.uk/%7Eucfagls/> >> >> > UK. WC1E 6BT. [w] http://www.freshwaters.org.uk >> > %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% >> > >> > >> >> >> -- >> PhD candidate in Computer Science >> Address >> 3 avenue lamine, cité ezzahra, Sousse 4000 >> Tunisia >> tel: +216 97 246 706 (+33640302046 jusqu'au 15/6) >> fax: +216 71 391 166 >> >> [[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. >> >> > > > -- > Henrique Dallazuanna > Curitiba-Paraná-Brasil > 25° 25' 40" S 49° 16' 22" O >-- PhD candidate in Computer Science Address 3 avenue lamine, cité ezzahra, Sousse 4000 Tunisia tel: +216 97 246 706 (+33640302046 jusqu'au 15/6) fax: +216 71 391 166 -- PhD candidate in Computer Science Address 3 avenue lamine, cité ezzahra, Sousse 4000 Tunisia tel: +216 97 246 706 (+33640302046 jusqu'au 15/6) fax: +216 71 391 166 [[alternative HTML version deleted]]
thanks, I'am not veru used with R!! regards 2010/8/21 Henrique Dallazuanna <wwwhsd@gmail.com>> Adel, > > read.table return a data.frame, Gavin showed, you need pass which column > will be plotted to hist. > scan return a vector. > > > On Sat, Aug 21, 2010 at 10:59 AM, Adel ESSAFI <adelessafi@gmail.com>wrote: > >> It works fine. >> >> Could you explain to me why it did not worked for read.table? >> >> regards >> Adel >> >> >> 2010/8/21 Henrique Dallazuanna <wwwhsd@gmail.com> >> >> Try this: >>> >>> a <- scan('dureetasks.txt') >>> hist(a) >>> >>> On Sat, Aug 21, 2010 at 10:32 AM, Adel ESSAFI <adelessafi@gmail.com>wrote: >>> >>>> Hi >>>> In fact, I searching for a simpler solution. I remember that I have >>>> done >>>> this without these functions (but I forgot) >>>> simply, is there any function that "force" R to take variable a as >>>> table ? >>>> >>>> Regards >>>> Adel >>>> >>>> >>>> >>>> > a=read.table("dureetasks.txt") >>>> > summary(a) >>>> V1 >>>> Min. : 1 >>>> 1st Qu.: 77 >>>> Median : 2658 >>>> Mean : 25802 >>>> 3rd Qu.: 42558 >>>> Max. :1575814 >>>> > hist(a); >>>> Error in hist.default(a) : 'x' must be numeric >>>> >>>> >>>> >>>> 2010/8/21 Gavin Simpson <gavin.simpson@ucl.ac.uk> >>>> >>>> > On Sat, 2010-08-21 at 11:37 +0200, Adel ESSAFI wrote: >>>> > > Hi list >>>> > > >>>> > > I loaded the content of a file dureetasks.txt to variable a. This >>>> file >>>> > > contains an interger per line. >>>> > > when I print a vector, it displays correctly. >>>> > > however, when I try to print the histogram, I get this error >>>> message >>>> > > >>>> > > > a=read.table("dureetasks.txt") >>>> > > > hist(a) >>>> > > Error in hist.default(a) : 'x' must be numeric >>>> > > >>>> > > Can you help please? >>>> > >>>> > class(a) >>>> > >>>> > str(a) >>>> > >>>> > > a <- data.frame(x = rnorm(100)) >>>> > > hist(a) >>>> > Error in hist.default(a) : 'x' must be numeric >>>> > >>>> > So I suspect a is a data frame with a single column/variable. You need >>>> > to pass hist the vector from /inside/ a that you want to plot: >>>> > >>>> > > with(a, hist(x)) >>>> > >>>> > is one way to do that. Note that 'x' is used because that is the name >>>> of >>>> > the variable (component really) in a that I want to plot: >>>> > >>>> > > names(a) >>>> > [1] "x" >>>> > >>>> > You will need to work out what the correct name is for the component >>>> you >>>> > want to plot. If there was no header to your text file then IIRC the >>>> > variable will be named X1, but run names(a) and see what it returns. >>>> > >>>> > Because we don't have your dureetasks.txt file, there is no way for me >>>> > to clarify that this is the problem and nothing else. If you can't >>>> send >>>> > us data at the very least use tools like str(a) and class(a), and >>>> > head(a) to show us what the data look like. >>>> > >>>> > HTH >>>> > >>>> > G >>>> > >>>> > > >>>> > > regards >>>> > > >>>> > > >>>> > > >>>> > > >>>> > > ______________________________________________ >>>> > > 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. >>>> > >>>> > -- >>>> > %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% >>>> > Dr. Gavin Simpson [t] +44 (0)20 7679 0522 >>>> > ECRC, UCL Geography, [f] +44 (0)20 7679 0565 >>>> > Pearson Building, [e] gavin.simpsonATNOSPAMucl.ac.uk >>>> > Gower Street, London [w] http://www.ucl.ac.uk/~ucfagls/<http://www.ucl.ac.uk/%7Eucfagls/> >>>> <http://www.ucl.ac.uk/%7Eucfagls/> >>>> >>>> > UK. WC1E 6BT. [w] http://www.freshwaters.org.uk >>>> > %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% >>>> > >>>> > >>>> >>>> >>>> -- >>>> PhD candidate in Computer Science >>>> Address >>>> 3 avenue lamine, cité ezzahra, Sousse 4000 >>>> Tunisia >>>> tel: +216 97 246 706 (+33640302046 jusqu'au 15/6) >>>> fax: +216 71 391 166 >>>> >>>> [[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. >>>> >>>> >>> >>> >>> -- >>> Henrique Dallazuanna >>> Curitiba-Paraná-Brasil >>> 25° 25' 40" S 49° 16' 22" O >>> >> >> >> >> -- >> PhD candidate in Computer Science >> Address >> 3 avenue lamine, cité ezzahra, Sousse 4000 >> Tunisia >> tel: +216 97 246 706 (+33640302046 jusqu'au 15/6) >> fax: +216 71 391 166 >> > > > > -- > Henrique Dallazuanna > Curitiba-Paraná-Brasil > 25° 25' 40" S 49° 16' 22" O >-- PhD candidate in Computer Science Address 3 avenue lamine, cité ezzahra, Sousse 4000 Tunisia tel: +216 97 246 706 (+33640302046 jusqu'au 15/6) fax: +216 71 391 166 [[alternative HTML version deleted]]
> It works fine. > > Could you explain to me why it did not worked for read.table?Because of what Gavin already explaied in his reply: read.table returns a data.frame and hist needs a vector. cu Philipp -- Dr. Philipp Pagel Lehrstuhl f?r Genomorientierte Bioinformatik Technische Universit?t M?nchen Wissenschaftszentrum Weihenstephan Maximus-von-Imhof-Forum 3 85354 Freising, Germany http://webclu.bio.wzw.tum.de/~pagel/