[R-sig-Geo] raster::setValues

Robert J. Hijmans r.hijmans at gmail.com
Thu May 6 18:10:49 CEST 2010


Dear Roman,

> rs object ends up empty when trying to apply rowvals. I would expect the rs
> object to have line number three populated with as many values as there are
> columns.

This is the case:

> values(rs)
 [1]  1  2  3  4  5  6  7  8  9 10
> dataContent(rs)
[1] "row"
> dataIndices(rs)
[1] 21 30

dataIndices returns the cell numbers of the first and last value.
Generally the only reason to set a row of values is to then write them
to disk. There is not much else you can do because only the values of
this row are stored, not the values for any other cells. If you want
those too:

rs[] = NA
rs[(2*ncol(rs)+1):(3*ncol(rs))] = 1:ncol(rs)

# or

rs[] = NA
start = cellFromRowCol(rs, 3,1)
end =  cellFromRowCol(rs, 3, ncol(rs))
rs[start:end] = 1:ncol(rs)

Robert


On Wed, May 5, 2010 at 11:58 PM, Roman Luštrik <roman.lustrik at gmail.com> wrote:
> When I run the sample code in ?setValues
>
> rs <- raster(ncol=10, nrow=10)
> vals <- 1:ncell(rs)
> rs <- setValues(rs, vals)
> rs <- clearValues(rs)
> rowvals <- 1:ncol(rs)
> rs <- setValues(rs, rowvals, 3)
>
> rs object ends up empty when trying to apply rowvals. I would expect the rs
> object to have line number three populated with as many values as there are
> columns. Or am I missing something very obvious here? Same behavior on 2.10
> and 2.11.
>
> Cheers,
> Roman
>
>
> --
> In God we trust, all others bring data.
>
>        [[alternative HTML version deleted]]
>
> _______________________________________________
> R-sig-Geo mailing list
> R-sig-Geo at stat.math.ethz.ch
> https://stat.ethz.ch/mailman/listinfo/r-sig-geo
>



More information about the R-sig-Geo mailing list