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

Removing punctuations from text using R

Here’s how I take your question, and an answer that is very close to @David Arenburg’s in the comment above. The extra space after [:punct:] is to add spaces to the string and the + matches one or more sequential items in the regular expression. This has the side effect, desirable in some cases, of …

Read more

Categories r Tags

How to set axis range R

Without data, I tried to reproduce your plot error: Which gives the following plot: Changing your plot to: Might solve your problem. Edit It seems that the formula changes to factors and orders it from 1 to the number of items, so I’ll use your trick on the y axis to solve this.