Skip to content
Back to formatted view

Raw Message

Message-ID: <BANLkTi=umLfUdo1HayLtYGWw+N1066vyEA@mail.gmail.com>
Date: 2011-04-27T11:30:13Z
From: E Hofstadler
Subject: calculations with vectors of unequal length

Hi there,

this is probably simple but I can't seem to figure it out by myself...

I have two dataframes (df.1 and df.2):

df.1 <- data.frame(year=factor(rep(1:3,3)), level=rep(letters[1:3],3),
number=c(11:19))
df.2 <- data.frame(year=factor(c(1:5)), number=c(21:25))

I would like to create a new variable df.1$new, which is supposed to
be the sum of each element of df.1$number and those elements of
df.2$number, where df.2$year equals df.1$year.

What would be the most efficient way of doing this?

Regards,
EH