Một vài code R hữu ích

There are some pieces of code that are so simple and obvious that they really ought to be included in base R somewhere.

Geometric mean and standard deviation ? a staple for anyone who deals with lognormally distributed data.

A drop option for `nlevels`

. Sure your factor has 99 levels, but how many of them actually crop up in your dataset?

A way of converting factors to numbers that is quicker than `as.numeric(as.character(my_factor))`

and easier to remember than the method suggested in the FAQ on R.

A “not in” operator. Not many people know the precedence rules well enough to know that `!x %in% y`

means `!(x %in% y)`

rather than `(!x) %in% y`

, but `x %!in% y`

should be clear to all.

I’m sure there are loads more snippets like this that would be useful to have; please contribute your own in the comments.

EDIT:

Thanks…

View original post 98 more words

Filed under: Uncategorized |

## Leave a Reply