how often should a computer be defragmented?
If you are on-line frequently you should regularly clean your PC with antivirus and with spyware/malware detection and removal tools. You should also use 'disk cleanup' at least monthly, to remove the debris and unnecessary files which accumulate on your PC.
If, after all that, you notice your PC is starting to slow down a bit, then you should defragment. There's no point in defragmenting unless you are suffering performance loss from file fragmentation. Defragmentation finds all the bits and pieces of your files and moves them all so that each file is together in the one spot. That speeds up file access, of course, because the heads of the hard drive don't need to jump about all over the place to read each file.
My suggestion would be to defragment only when you need to (3-6 months). On-line activity will cause a reasonable amount of ‘temporary’ files to be written to the hard drive, and may shorten the period between defrags for you, but there’s no fixed formula you need to follow.