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

How can I change the name of a data frame

The truth is that objects in R don’t have names per-se. There exists different kinds of environments, including a global one for every process. These environments have lists of names, that point to various objects. Two different names can point to the same object. This is best explained to my knowledge in the environments chapter … Read more