Simple question. Consider this vector:
[1] 378 380 380 380 380 360 187 380
How could we determine what are the numbers that differs from the others in that list? In that case it would be 378 360 and 187. Any ideas? I’m aware that the solution might not be simple…
I’m learning R and working on a dataset for my research, so it’s != homework.
Any help would be greatly appreciated !
You can find the most frequent entry by using
table()andwhich.max(), you can then index the original vector with a logical vector containing the non-equal entries like so: data[data!=mostfrequent]. You can get help by?table()and?which.max(), please comment if you need more.Your sample vector
Find the frequency of each number in it with
table. For convenience later on, we convert it to be a data frame.which.maxlets us locate the modal value (the most common one).The other values can then be found via indexing.