Hi Sandra, Terribly ugly, but this way at least you don't have to know which years are missing, etc.:
dat <- data.frame(year = c(1981,1984,1985,1986), size = c(1,2,3,4)) year_ <- data.frame(year = seq(1981,1986,1)) year_dat <- merge(year_, dat, by = "year", all=T) na_s <- subset(year_dat, is.na(size) == "TRUE") na_s_zeros <- cbind(na_s, size = rep(0, length(na_s[,1])))[,-2] newdat <- rbind(subset(year_dat, !is.na(size) == "TRUE"), na_s_zeros) hth, Scott On Wednesday, February 23, 2011 at 4:22 PM, saba wrote: > > Hello everyone, > > I have the following problem, I have a dataframes that looks like this: > > fire$Year fire$Size > 1 1981 1738.0 > 2 1984 2228.1 > 3 1985 38963.3 > 4 1986 2223.4 > 5 1987 3594.6 > 6 1988 1520.0 > ... > > What I would like to do is copy the values from the fire$Size colum and put > it into a new df but with "0" for the years that are missing. The result > should look like this: > > year size > > 1981 1738.0 > 1982 0 > 1983 0 > 1984 2228.1 > ... > > First I tried to merge the two dataframes > temp <-merge(fire.sum,fire2, by.x="fire$Year", by.y="year") > > but then it only gives me the years that are the same. So I thought it might > be easier to just copy them? > > Any help is appreciated, thank you so much > Cheers > Sandra > > -- > View this message in context: > http://r.789695.n4.nabble.com/copy-values-from-one-dataframes-into-another-tp3321805p3321805.html > Sent from the R help mailing list archive at Nabble.com. > > ______________________________________________ > R-help@r-project.org mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. > [[alternative HTML version deleted]] ______________________________________________ R-help@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code.