Skip to content

some help

3 messages · Rui Barradas, dattel_palme, jim holtman

#
Hello,

Why answer to just me? You should keep it in the R-Help list, the odds 
of getting more (and hopefully better) answers is bigger.

Anyway, with data examples it's much easier to do something. I hope the 
code is self explanatory, except maybe for the use of scan(), not 
read.table. scan() reads in vectors, so there's no need to stack the 
columns anymore, they're just one big vector. Another thing is that 
around half of the values are zeros, and those don't show up in the 
graph you've posted, so I've filtered them out.

fdir <- "Asciis"  # change if needed
curr_dir <- setwd(fdir)  # save current directory and set working dir
fls <- list.files()
lst <- scan(fls[1], dec=",")
ndv <- scan(fls[2], dec=",")

str(lst)
str(ndv)

i0 <- ndv > 0 & lst > 0
ndv0 <- ndv[i0]
lst0 <- lst[i0]

brks <- seq(0, 1, by = 0.01)
group <- cut(ndv0, breaks = brks)

mins <- tapply(lst0, group, FUN = min) # one min per group
maxs <- tapply(lst0, group, FUN = max) # one max per group

fit.min <- lm(mins~brks[-1L])
fit.max <- lm(maxs~brks[-1L])

dev.new()
plot(ndv0, lst0, pch=".")
abline(fit.min, col = "blue")
abline(fit.max, col = "red")

#----  Now with ave(). It returns one min/max per element in lst0,
#----  so you'll have a vector as long as the original lst0, with the 
min/max
#----  corresponding values.

mins2 <- ave(lst0, group, FUN = min)  # one min per element of lst0
maxs2 <- ave(lst0, group, FUN = max)  # one max per element of lst0

fit.min2 <- lm(mins2~ndv0)
fit.max2 <- lm(maxs2~ndv0)

dev.new()
plot(ndv0, lst0, pch=".")
abline(fit.min2, col = "blue")
abline(fit.max2, col = "red")


Hope this helps,

Rui Barradas
Em 04-11-2012 10:36, Stefan M?hlbauer escreveu:
22 days later
#
Hey

The code need some corrections and I would kindly ask for help.

Say:
I have a table with two columns:
col1=LST and col2=NDVI
i would like to sort all data by NDVI. 
in reality the NDVI ranges between 0 and 1 (although some values might be
minus also).
I want to sort by NDVI values and then make 100 intervals of 0.01 ndvi.
therefore the first inerval is 0.01-0.02, the second 0.02-0.03 and so on..
for each interval I would like to get the highest (max) and lowest (min)
value of LST. 
It would be very helpful if this values can be written in a seperate
table/file. 

Thanks you very much for help!
Stefan



--
View this message in context: http://r.789695.n4.nabble.com/some-help-tp4648316p4650844.html
Sent from the R help mailing list archive at Nabble.com.
#
try this:  (provide sample data next time)
LST       NDVI
1  0.86542839 0.95129647
2  0.88910058 0.75971649
3  0.44086718 0.86532140
4  0.99879370 0.05511501
5  0.02401490 0.92282834
6  0.56026534 0.80915721
7  0.65051596 0.03606430
8  0.25897388 0.61624609
9  0.07873261 0.85179368
10 0.09829056 0.91198307
LST       NDVI        part
1 0.8654284 0.95129647 (0.95,0.96]
2 0.8891006 0.75971649 (0.75,0.76]
3 0.4408672 0.86532140 (0.86,0.87]
4 0.9987937 0.05511501 (0.05,0.06]
5 0.0240149 0.92282834 (0.92,0.93]
6 0.5602653 0.80915721  (0.8,0.81]
$`(0,0.01]`
[1] 0.01945995 0.83500402

$`(0.01,0.02]`
[1] 0.02267906 0.69770971

$`(0.02,0.03]`
[1] 0.01287795 0.75275416

$`(0.03,0.04]`
[1] 0.1402162 0.9960408

$`(0.04,0.05]`
[1] 0.007688249 0.691519845

$`(0.05,0.06]`
[1] 0.1047314 0.9987937

$`(0.06,0.07]`
[1] 0.002181767 0.990990999

$`(0.07,0.08]`
[1] 0.08271319 0.87609409

$`(0.08,0.09]`
[1] 0.1174585 0.8931750

$`(0.09,0.1]`
[1] 0.2331289 0.8485212
On Mon, Nov 26, 2012 at 9:56 AM, dattel_palme <dattel_palme at yahoo.de> wrote: