[R] Merging two columns of unequal length

Bailey Hewitt bailster at hotmail.com
Tue Dec 13 00:41:01 CET 2016


Dear R Help,


I am trying to put together two columns of unequal length in a data frame. Unfortunately, so far I have been unsuccessful in the functions I have tried (such as cbind). The code I am currently using is : (I have highlighted the code that is not working)


y<- mydata[,2:75]

year <- mydata$Year

res <- data.frame()

for (i in 1:74){

  y.val <- y[,i]

  lake.lm= lm(y.val ~ year)

  lake.res=residuals(lake.lm)

  new.res <- data.frame(lake.res=lake.res)

  colnames(new.res) <- colnames(y)[i]

#cbind doesn't work because of the unequal lengths of my data columns

  res <- cbind(res, new.res)

  print(res)

}


mydata is a csv file with "Year" from 1950 on as my first column and then each proceeding column has a lake name and a day of year (single number) in each row.


Please let me know if there is any more information I can provide as I am new to emailing in this list. Thank you for your time!


Bailey Hewitt

	[[alternative HTML version deleted]]



More information about the R-help mailing list