September 2010
M T W T F S S
« Aug    
 12345
6789101112
13141516171819
20212223242526
27282930  

ave

I discovered a new, very useful, R function yesterday: ave.

This is what it does: “Subsets of ‘x[]‘ are averaged, where each subset consist of those observations with the same factor levels.”

But interestingly, you can use any function other than average. The output of that function is set against each observation.

I wanted to, for example, stick [...]

Basic skills to use a spreadsheet software

Two students of social sciences who had so far used computers for limited, specific tasks recently asked me for some kind of a course outline that they should cover to pick up basic skills for using a spreadsheet software. I prepared the list and thought it may interest some others. Hence this post.

1. Basic structure [...]

Moving average/median

?rollmean (package=zoo)?rollmedian [...]

“relevel” factors when using them to create dummy variables

?relevel

: The levels of a factor are re-ordered so that the level specified
by ‘ref’ is first and the others are moved down. This is useful
for ‘contr.treatment’ contrasts which take the first level [...]

Reading large tables into R

Here are some useful tips on [...]

Reading large datasets in R

Farnsworth has discussed with an example a faster way of reading large files. It would be nice if some of you tried to implement it to read schdata.txt

Also, let us collectively mine the documentation/r-help for more resources [...]

Reading data from microsoft access files in linux

Some of the Census 2001 data are in microsoft access files (having filename extensions .mdb). A microsoft access file can have several tables inside, each of which contains data. There is a software called mdbtools that can be used to read access files.

The command mdb-tables can be used to see the names of tables and the [...]

Dropping columns in subset command

Use “select=c(var1,var2)” in the subset command to select var1 and var2.

Use “select=-c(var1,var2)” in the subset command to drop var1 and var2.

Technorati [...]

Renaming variables in a dataframe

There is no direct command in R for renaming variables and that may make it less than obvious for some people. Of course, once you know, it is simple. The following command does the trick.

names(dataframe)[names(dataframe)=="oldvariablename"]<-”newvariablename”

 

VR

 

Use reshape to tabulate

Package reshape is meant for aggregating, reshaping and tabulating data.Tabulation is done in two steps: melt and cast. Read help for these functions.

melt(sl1,id.var=,measure.var=”foo”)->sl2

This will create a dataframe sl2 which will have all the variablesin sl1 and “foo” being reorganised for casting later. See head(sl2) to see the form it takes.

The following command takes [...]