Arslan Rehman
2016-Feb-20 22:10 UTC
[R] Beginner: error when I plot histogram from imported table
Hello R users, #I import a txt file from following code:> da=read.table("C:/Users/agohir/Desktop/ARModel.txt",header=T) > head(da) ytsim1 3.04497412 -0.95401593 0.25043094 -0.69580895 1.95196236 1.4400745#Now, I get error for following code:> hist(da,freq=FALSE,nclass=30,ylim=c(0,60),col="blue")Error in hist.default(da, freq = FALSE, nclass = 30, ylim = c(0, 60), : 'x' must be numeric#when I check imported data it mention it is numeric?> str(da)'data.frame': 999 obs. of 1 variable: $ ytsim: num 3.045 -0.954 0.25 -0.696 1.952 ..#If not, how do I convert and then plot histogram. #I also want to plot a probability density line afterwards Any help is appreciated. Thank you,Arslan [[alternative HTML version deleted]]
Jeff Newmiller
2016-Feb-21 05:18 UTC
[R] Beginner: error when I plot histogram from imported table
You should compare the output of str(da) with the output of str(1:10)... da is a data.frame that contains one column (a numeric vector). Data.frames are not numeric, they are lists of columns. Replace da with da$ytsim1 in your call to hist. -- Sent from my phone. Please excuse my brevity. On February 20, 2016 2:10:43 PM PST, Arslan Rehman <goheer_ at hotmail.com> wrote:>Hello R users, >#I import a txt file from following code: >> da=read.table("C:/Users/agohir/Desktop/ARModel.txt",header=T) >> head(da) ytsim1 3.04497412 -0.95401593 0.25043094 -0.69580895 >1.95196236 1.4400745 >#Now, I get error for following code: >> hist(da,freq=FALSE,nclass=30,ylim=c(0,60),col="blue")Error in >hist.default(da, freq = FALSE, nclass = 30, ylim = c(0, 60), : 'x' >must be numeric > >#when I check imported data it mention it is numeric? >> str(da)'data.frame': 999 obs. of 1 variable: $ ytsim: num 3.045 >-0.954 0.25 -0.696 1.952 .. > >#If not, how do I convert and then plot histogram. >#I also want to plot a probability density line afterwards >Any help is appreciated. >Thank you,Arslan > > > [[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.[[alternative HTML version deleted]]