Skip to content
Prev 157334 / 398506 Next

How to update a column in a dataframe, more simply...

First of all, what you have will not work since you also have to
subset the RHS of the equation:

data$score[data$type=="1" &
data$year=="2001"]<-data$score[data$type=="1" & data$year=="2001"] *
0.111

Another way is to construct a matrix of the values you want to search
for and change: (not tested)

change <- rbind(c(1, 2001, 0.111),
				c(1, 2002, 0.222),
				c(1, 2003, 0.333),
				c(2, 2001, 1.111),
				.....)
for (i in seq(nrow(change))){
	select <- data$type == change[i,1] & data$year == change[i,2]
	data$score[select] <- data$score[select] * change[i,3]
}
On Fri, Sep 26, 2008 at 6:35 PM, Mark Na <mtb954 at gmail.com> wrote: