Skip to content
Back to formatted view

Raw Message

Message-ID: <20110118172746.GA30702@praha1.ff.cuni.cz>
Date: 2011-01-18T17:27:46Z
From: Petr Savicky
Subject: matrix manipulations
In-Reply-To: <BAY147-w43238DD8E6AF248A340D7C3F40@phx.gbl>

On Mon, Jan 17, 2011 at 10:37:42PM +0000, Monica Pisica wrote:
> 
> Hi,
> 
> I've got 2 very good solutions, thank you very much. One, from Henrique Dallazuanna using the library reshape and one line of code - although it will take me quite some time to understand it. Here it is what he sent:
> 
> library(reshape)
> xtabs(rowSums(cbind(value.x, value.y), na.rm = TRUE) ~ X1 + X2, merge(melt(m1), melt(m2), by = c('X1', 'X2'), all = TRUE), exclude = FALSE)
> 
> 
> The other is from Phil Spector ( code below) that i can understand quite easily, although until now to my shame i never quite used factor levels and their properties and i don't know their uses and possibilities. Until now i tried to avoid them and transform them in something else (like character strings).

Let me add a comment on factors.

Character vectors are easier to manipulate and factors carry additional
information. A balance between their uses depends on the application. A possible
strategy is to use character vectors, when the sequence of categorical data
should be manipulated, and convert to a factor, when needed. There is an R Wiki
page with some tips concerning factors at
  http://rwiki.sciviews.org/doku.php?id=tips:data-factors:factors

Petr Savicky.