How to combine two dataframes in R? -


i'm trying load csv file , shows dates, wages , percentage change. unfortunately 1 of datasets has 42 rows 3 columns other has 41 rows 2 columns. data file here

so tried these 2 no chance

rbind.fill(data,datadiff) bind_rows(data,datadiff) 

once try combine them result below, second dataframe starts first dataframe ends http://imgur.com/a/pr8ez

so there way show them , tidier? here code:

location <- read.csv("c:/users/melik/desktop/sydney-melbourne-rent-master/average_wages.csv", stringsasfactors=t,header=true) x1 <- as.date(location[,1],format = "%d/%m/%y") data <- data.frame(x1, x2 <- location[,2],x3 <- location[,3]) colnames(data) <- c("date","sydney wages","melbourne wages") x2diff <- diff(data[,2])/data[-nrow(data),2] * 100 x3diff <- diff(data[,3])/data[-nrow(data),3] * 100 colnames(datadiff) <- c("sydney difference","melbourne difference") datadiff <- data.frame(x2diff,x3diff) rbind.fill(data,datadiff) 

as mentioned in comments of op, adding row nas datadiff , cbind effective way.

dates = sample(seq(as.date('2013/01/01'), as.date('2016/01/01'), by="day"), 40) sydneywages = runif(n = 40, min = 1300, max = 1600) melbournewages = runif(n = 40, min = 1300, max = 1600)  startdata = data.frame(dates, sydneywages, melbournewages) x2diff <- diff(startdata[,2])/startdata[-nrow(startdata),2] * 100 x3diff <- diff(startdata[,3])/startdata[-nrow(startdata),3] * 100  datadiff = data.frame(x2diff, x3diff) datadiff = rbind(datadiff, na)  finaldata = cbind(startdata, datadiff)  #alternatively can add date datadiff , use merge #this possible if every date unique datadiff = cbind(dates, datadiff) finaldata = merge(x = startdata, y = datadiff, = "dates", sort = f) 

Comments

Popular posts from this blog

Is there a better way to structure post methods in Class Based Views -

performance - Why is XCHG reg, reg a 3 micro-op instruction on modern Intel architectures? -

jquery - Responsive Navbar with Sub Navbar -