What is the difference between require() and library()?

In addition to the good advice already given, I would add this: It is probably best to avoid using require() unless you actually will be using the value it returns e.g in some error checking loop such as given by thierry. In most other cases it is better to use library(), because this will give an error message at … Read more

How to prevent scientific notation in R?

To set the use of scientific notation in your entire R session, you can use the scipen option. From the documentation (?options): So in essence this value determines how likely it is that scientific notation will be triggered. So to prevent scientific notation, simply use a large positive value like 999:

Categories r Tags

use first row data as column names in r

I have a dirty dataset that I could not read it with header = T. After I read and clean it, I would like to use the now first row data as the column name. I tried multiple methods on Stack Overflow without success. What could be the problem? The dataset t1 should look like … Read more

Categories r

How to unload a package without restarting R

Try this (see ?detach for more details): It is possible to have multiple versions of a package loaded at once (for example, if you have a development version and a stable version in different libraries). To guarantee that all copies are detached, use this function. Usage is, for example or

How to melt and cast dataframes using dplyr?

The successor to reshape2 is tidyr. The equivalent of melt() and dcast() are gather() and spread() respectively. The equivalent to your code would then be If you have magrittr imported you can use the pipe operator like in dplyr, i.e. write Note that you need to specify the variable and value names explicitly, unlike in melt(). I find the syntax of gather() quite convenient, because you can just specify the columns you … Read more

Categories r