Skip to content
Prev 366120 / 398502 Next

Merging two columns of unequal length

Hi Bailey,
I may be misunderstanding what you are doing as I can't work out how
you get unequal column lengths, but this may help:

myval<-matrix(sample(1:365,740,TRUE),ncol=74)
mydata<-as.data.frame(cbind(1950:1959,myval))
lakenames<-paste(rep(LETTERS[1:26],length.out=74),
 rev(rep(letters[1:25],length.out=74)),
 rep(letters[1:24],length.out=74),sep="")
names(mydata)<-c("Year",lakenames)
res<-vector("list",74)
for (i in 1:74){
 thisval<-mydata[,i+1]
 lake.lm<-lm(thisval ~ Year,mydata)
 res[[i]]<-residuals(lake.lm)
}
# this will cause an error with as.data.frame
res[[20]]<-res[[20]][-1]
# pad the short column with NA
res<-lapply(res,function(x,length.out) x[1:length.out],10)
res.df<-as.data.frame(res)
names(res.df)<-lakenames
print(res.df)

Jim
On Tue, Dec 13, 2016 at 10:41 AM, Bailey Hewitt <bailster at hotmail.com> wrote:
Message-ID: <CA+8X3fVOsGX9FwtNsHq8XBQQP1fxazAc9_XgRtCAtM9y-rakgg@mail.gmail.com>
In-Reply-To: <YQBPR01MB011360B9FA0E35D548CDA117D9980@YQBPR01MB0113.CANPRD01.PROD.OUTLOOK.COM>