I am trying to read a tif in R. This tif has 4 columns in its attribute table as you can see in the image. However I am only interested in column 4 (WF) to plot and work in R. My problem is that when I call the raster in R, automatically it plots and works on the Value column (according to values of the scale bar). The dbf of this raster is also attached here. Do you know how can I do to specify the column WF I want to work in?
We can't see for sure that your data in R corresponds to your image, but if it does you probably want either of
## load just one band, the 3rd library(raster) r <- raster("myfile.tif", band = 3)
## load all bands, but select only the 3rd r <- brick("myfile.tif")[]
I'm assuming there's three bands, and by position WF is the third. The first column is the cell index (presumably) and is only implicit in the file and in this raster format.
EDIT: it's not clear from the OP that this is the case, it doesn't mention software or include any example files, but from comments looks like a loose connection between a DBF (simple database table file) and the values of the raster.
If so, read the DBF with
read.dbf() and index it with the values of the raster:
## WARNING: untested dd <- read.dbf("myfile.dbf")[raster::values(raster::raster("myfile.tif")), ] ## to put the WF value (assuming there is one) onto the raster rr <- raster::setValues(raster::raster("myfile.tif"), dd$WF)
That last construct assumes there's no missing values and all indexes are sensible given
nrow(dd). To really answer this needs a real world example to check this stuff.