[R] Finding ranges on a per-row basis from several objects
jim at bitwrit.com.au
Fri Feb 5 11:44:36 CET 2010
On 02/05/2010 09:21 PM, Steve Murray wrote:
> Dear all,
> I'm attemping to find the overall range of values from column 5 of a series of data frames, on a per-row basis, and assign the results to a new object. At present, I'm only able to receive the overall range of all values, whereas I'm intending to get the results of the range for each corresponding row. This is what I have so far:
> for (i in seq(nrow(dframe)))
> range_models<- rbind(range(c(dframe1[i,5]), range(dframe2[i,5]), range(dframe3[i,5]), range(dframe4[i,5]), range(dframe5[i,5]), range(dframe6[i,5])))
> If it's of any help, the structure of each of the data frames is:
> 'data.frame': 61538 obs. of 6 variables:
> $ Latitude : num -0.25 -0.25 -0.25 -0.25 -0.25 -0.25 -0.25 -0.25 -0.25 -0.25 ...
> $ Longitude : num -48.8 -49.2 -49.8 -50.2 -50.8 ...
> $ Runoff_fut : num 1549 1335 1254 1111 1066 ...
> $ Runoff_bline: num 1877 1719 1550 1438 1362 ...
> $ Difference : num -328 -383 -296 -327 -297 ...
> $ PerctDiff : num -17.5 -22.3 -19.1 -22.7 -21.8 ...
> So, just to clarify, I'm trying to find the range of values for row 1 based on dframe1 through to dframe6, then row 2, row 3 etc etc. and put the range results for each row into a new object of equal row number to the dframe objects.
If I get the idea, you want to get the ranges of "Difference" across the
data frames a row at a time. I think this will work:
You may have to add "na.rm=TRUE" if there are NAs.
More information about the R-help