Skip to content
Prev 306986 / 398506 Next

R combining vectors into a data frame but without a continuous common variable

Hello,

Try the following.


url1 <- "http://r.789695.n4.nabble.com/file/n4644986/Landeck_vec.txt"
url2 <- "http://r.789695.n4.nabble.com/file/n4644986/Kaurnetal_vec.txt"

dat1 <- read.table(url1, header = TRUE)
dat2 <- read.table(url2, header = TRUE)

str(dat1)
str(dat2)  # Precip is a factor, so convert to numeric
dat2$Precip <- as.numeric(levels(dat2$Precip)[dat2$Precip])

dat1$Landeck <- as.Date(dat1$Landeck, format = "%d.%m.%Y")
dat2$Date <- as.Date(dat2$Date, format = "%d.%m.%Y")

dat3 <- merge(dat1, dat2, by.x = "Landeck", by.y = "Date")
str(dat3)
head(dat3, 20)  # See first 20 rows


Hope this helps,

Rui Barradas
Em 04-10-2012 12:18, lucy88 escreveu: