0

I'm trying to extract pixel value using the extract() function from raster package in R and get the following error, bellow in my code bellow a well, where: df$PixelNumber is the "cell number value". The error :

Error in (function (classes, fdef, mtable) : unable to find an inherited method for function ‘extract’ for signature ‘"character", "numeric"’

the code I'm using:

vec=as.vector(as.numeric(as.matrix(df$PixelNumber)));
rast = file.choose();
VlaueSlope=extract(x= rast, vec)

What could I be doing wrong in the extract() code that cannot get the pixel value in the variable VlaueSlope.

Jeffrey Evans
32.2k2 gold badges49 silver badges97 bronze badges
asked Mar 28, 2020 at 9:11
1
  • Could you try vec = as.numeric(as.matrix(df$PixelNumber))) ? Commented Mar 28, 2020 at 11:13

1 Answer 1

2

The error:

 Error in (function (classes, fdef, mtable) : 
 unable to find an inherited method for
 function ‘extract’ for signature ‘"character", "numeric"’

is saying you are calling extract with a "character" argument and a "numeric" argument. How are you calling it? Let's see...

VlaueSlope=extract(x= rast, vec)

so what is rast? Let's see:

rast = file.choose();

rast is the file name it is NOT the raster data. You need to read in the raster using something like:

rasterpath = file.choose()
rast = raster(rasterpath)

and then you can extract the pixel values if everything else is correct.

In summary: try and understand error messages, read the documentation for functions, and check your arguments match the ones documented.

answered Mar 28, 2020 at 13:21
1
  • Yes, indeed I had has this mistake now works!!! Thanks!! how can In get the rather of only all (the cell original cell values of the raster) but only where the are points? thanks Commented Mar 29, 2020 at 8:09

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.