The word rem seems to mean all sorts of things depending on the context — sometimes it means "the thing", sometimes "it", and sometimes rem can be entirely omitted from the English translation. What is the rule for determining exactly what it means?
There is no simple (or even complicated) rule you could follow. In some cases the word res is ambiguous and you cannot narrow the options down to one.
The word can mean so many things that instead of learning all the possible translations I encourage trying to get a feeling to what kinds of things it can mean. If you encounter it in a Latin text, try to figure out what the text means and then express that meaning in English. There may be an English word or expression corresponding to res, but is not necessary. This is different from simple-mindedly translating the text word by word.
There is no definitive definition for res, and there is no way around that. 'Thing' is a good general translation, but sometimes it doesn't work at all. Sometimes choosing a different translation from a dictionary dramatically changes the meaning. To translate well, you really need to figure out from the context what the writer is trying to express.
You will probably get a better feeling of the word by working with examples. If some use contexts feel confusing to you, post another question and ask how res and the sentence containing it should be translated.
@JoonasIlmavirta gave an excellent answer. I'll just add that one thing that can help is understanding that the Romans tended to talk about concrete things rather than abstract things, and when an abstraction comes up ("matter," "difficulty," etc., etc.), rēs is often the word they ended up choosing. This is a gross generalization, of course, but it's one way to understand why it can mean so very many different things.
From the preface of Robert Millington's 1882 Introduction to Latin Prose Composition:
"These modern times, exhibiting as they do such a varied profusion of general and philosophical knowledge and abstract thought, materially increase the difficulty of Latin writing. The difficulty is further added to by . . . the comparative absence of [Latin] abstract ideas and terms. . . . Hence, too, arose the very extensive use of such words as res and ratio in a variety of meanings depending greatly on the general sense of the passage."
Agree that res / rem can stand for whatever the context demands. See Horace, Epistles I.I.65:
Rem facias, rem si possis, recte, si non quocumque modo, rem.
In this case "rem" means money.