How to create lag variables

In base R the function lag() is useful for time series objects. Here you have a dataframe and the situation is somewhat different. You could try the following, which I admit is not very elegant: An alternative consists in using the Lag() function (with capital “L”) from the Hmiscpackage:

Categories r Tags ,

Convert data.frame column to a vector?

I’m going to attempt to explain this without making any mistakes, but I’m betting this will attract a clarification or two in the comments. A data frame is a list. When you subset a data frame using the name of a column and [, what you’re getting is a sublist (or a sub data frame). If you want … Read more

Does the c command create a row vector or a column vector by default in R

Neither. A vector does not have a dimension attribute by default, it only has a length. If you look at the documentation on matrix arithmetic, help(“%*%”), you see that: Multiplies two matrices, if they are conformable. If one argument is a vector, it will be promoted to either a row or column matrix to make the … Read more

Categories r Tags

Transposing in dplyr

I think you want tidyr rather than dplyr: Using this, you can specify your groupings – and you can add on select(-group) to remove them later.

Installing R on Android

Install GNURoot from Google Play Install Gnuroot Wheezy from Google Play. See http://www.linux-magazine.com/ Online/Blogs/Productivity-Sauce/GNURoot-Linux-on-Android-No-Root-Required for more help. Update the package repositories (twice!):apt-get update apt-get update Block updates to system Perl:apt-mark hold perl-base Install R:apt-get install r-base Install all available cran packages from the Debian repositories:apt-get install r-cran* Start R from the command line:R source http://www.r-ohjelmointi.org/?p=1434

Error: x must be atomic for ‘sort.list’

From the output of str(cc2), the variable inside of the data.table, V1, is itself a list. This means that cc2 is a nested list of length 1. The error is occurring because table calls sort.list, which requires an atomic vector as input. Try using unlist: unlist will (recursively) extract elements from their list containers. So unlist(cc2) will return a vector, which works directly … Read more

Categories r Tags