[R] Combine variables of different length

R. Michael Weylandt michael.weylandt at gmail.com
Tue Nov 1 16:14:51 CET 2011


Perhaps something like this:

X = jitter(1:10)
Y = jitter(3*X-5, factor = 3)
X[3] = NA
m = lm(Y~X)$fitted.values

fits <- rep(NA, length(X)); fits[as.numeric(names(m))] <- m;

cbind(X,Y,fits)

Michael

On Tue, Nov 1, 2011 at 8:52 AM, Johannes Radinger <JRadinger at gmx.at> wrote:
> Hi,
>
> I have got a dataset with
> the variables Y,X1,X2,X3.
> Some of these variables contain NAs. Therefore
> incomplete datasets aren't recognized when
> I am doing a regression like:
>
> model <- lm(Y~X1+X2+X3)
>
> so the resulting vector of resid(model) is
> obviousely shorter then the original variables.
>
> How can I combine the residuals-vector with
> the original dataset (Y,Xi,...). I recognize
> that the residuals give also a kind of an index
> like from the row names (2,5,7,8,9,12)...
>
> Is it possible to use in such a case the
> data.frame command? Or what is the best
> way to attach the resulting residuals back to
> the original dataframe with incomplete datasets?
>
> thanks
>
> /Johannes
> --
>
> ______________________________________________
> R-help at 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.
>



More information about the R-help mailing list