If your matrix really exists this will work, though you'd be computing the standard deviations of the rows, columns would be MARGIN = 2.
Does this command return TRUE?
When you get the error are you running this code in an interactive environment (e.g. an R console or from a source editor) or are you trying to build a document (knitting to PDF or html)?
If M doesn't exist, that's your problem, you need to get M.
If M does exist and you are running the code interactively, then I am at a loss as to why you are getting that error.
If M does exist and you are getting this error while trying to build a document, this is actually very common. It means you ran some code interactively to create the M object in your environment, but there is no code in your R Markdown document which creates an M object (or it is located somewhere further down the document after you are trying to use it).
To answer the other part of your question, R won't care if data is missing, sd() will return NA for any column with missing data. If you wanted to ignore missingness and compute the standard deviations anyway, you would update the command to be,