Dear all, I have a column within a dataframe of values which range between 1 and 2. I want to display graphically the distribution of these values (i.e. are they clustered towards either exteme? Or spread evenly?). What is a good way of doing this in R? I've tried a few things, including using the 'hist' command, but receive the following error message:> hist(urban.long[3])Error in hist.default(urban.long[3]) : 'x' must be numeric ...which is strange because all the values *are* numeric! I also tried to create a scatter graph, but it's difficult as there isn't anything obvious to go on the 'y' axis. I've tried to create some kind of 'frequency' axis using the 'sequence' function, but receive the following:> plot(seq(0,1000,100),urban.long[3])Error in xy.coords(x, y, xlabel, ylabel, log) : 'x' and 'y' lengths differ ...which is probably because I'm unable to tell how many of each value there are (which invalidates the 'sequence' argument perhaps?). Maybe I'm taking the wrong approach! I'd be very grateful if someone could put me on the right tracks and guide me with the R commands. Many thanks for any help offered, Steve
Steve Murray <smurray444 <at> hotmail.com> writes:> > > Dear all, > > I have a column within a dataframe of values which range between 1 and 2. Iwant to display graphically the> distribution of these values (i.e. are they clustered towards either exteme?Or spread evenly?). What is> a good way of doing this in R? > > I've tried a few things, including using the 'hist' command, but receive thefollowing error message:> > > hist(urban.long[3]) > Error in hist.default(urban.long[3]) : 'x' must be numeric > > ...which is strange because all the values *are* numeric! >hist, plot(density(x)), rug ... are you sure that your column really is numeric and hasn't gotten turned into a factor because of a glitch? what do you get from class(urban.long[3]) ? Ben Bolker
Dear Phil and Jorge, Many thanks for your quick replies. I found that:> hist(urban.long[,3]) worked and displayed the data as I hoped. This reveals that the data are strongly distributed towards the value '1', and the other bars on the histogram are difficult to distinguish from each other as they are very small. I therefore wish to examine all values of urban.long[,3] which are greater than 1. I have tried the following, but receive error messages each time:> hist(urban.long[,3]>1)Error in hist.default(urban.long[, 3]> 1) : 'x' must be numeric> hist(urban.long[urban.long[,3]>1])Error in `[.data.frame`(urban.long, urban.long[, 3]> 1) : undefined columns selected> hist(urban.long[urban.long[,3]>1])Error in `[.data.frame`(urban.long, urban.long[, 3]> 1) : undefined columns selected> hist(as.numeric(urban.long[urban.long[,3]>1]))Error in `[.data.frame`(urban.long, urban.long[, 3]> 1) : undefined columns selected> hist(as.numeric(as.character(urban.long[urban.long[,3]>1])))Error in `[.data.frame`(urban.long, urban.long[, 3]> 1) : undefined columns selected Here is some information about the data:> class(urban.long[,3])[1] "numeric"> str(urban.long[,3])num [1:67609] 1 1 1 1 1 1 1 1 1 1 ... I'm probably doing something fairly obvious wrong - if anyone could point this out to me then I'd be very thankful! Many thanks again, Steve
> I have a column within a dataframe of values which range between 1 and > 2. I want to display graphically the distribution of these values > (i.e. are they clustered towards either exteme? Or spread evenly?). > What is a good way of doing this in R? > > I've tried a few things, including using the 'hist' command, but > receive the following error message: > > > hist(urban.long[3]) > Error in hist.default(urban.long[3]) : 'x' must be numeric > > ...which is strange because all the values *are* numeric!Your approach is correct with one minor glitch: urban.long[3] is not a vector but again a data.frame. Try hist(urban.long[,3]) That should do what you want. cu Philipp -- Dr. Philipp Pagel Lehrstuhl f?r Genomorientierte Bioinformatik Technische Universit?t M?nchen Wissenschaftszentrum Weihenstephan 85350 Freising, Germany http://mips.gsf.de/staff/pagel