[R] Odp: cbind with vectors of different lengths?

From: Petr PIKAL <petr.pikal_at_precheza.cz>
Date: Thu, 10 Jun 2010 10:52:24 +0200

Hi

you shall use na.action = "na.exclude" option in your lm call?

Regards
Petr

r-help-bounces_at_r-project.org napsal dne 10.06.2010 01:12:55:

>
> Hello R help
> I have a dataframe, with 71 samples (rows) and 30 variables. I got
linear
> models for some of the variables, and I want to join fitted and
residuals of
> these models to the data frame. Sometimes, these vectors have the same
length
> of the dependant variable, but in a few cases, NA values can be found on
my
> data, and therefore, both fitted and residuals have a few rows less than
the
> original data frame. As I try cbind, R answers with error, because both
> vectors have different lenghts. I have tried with merge but... suddenly
I had
> a lot of rows of repeated values. I think (with my small idea of R and
the
> manuals and helps I did read) that first, I have to force residuals and
fitted
> of my model to be a data frame.
> >as.data.frame(fitted(lm))
> this gives, for example
> [1] 1.1
>
>
> [3] 3.8
>
>
> [4] 1.3
>
> [5] 0.9
>
> instead of the original fitted(lm)
> 1 3 4 5
> 1.1 3.8 1.3 0.9
>
>
> that I want to join to my data frame
> [1] 17.0
> [2] 15.2
>
>
> [3] 17.3
>
>
> [4] 15.0
>
> [5] 17.4
> as you can see, row 2 does not exist in fitted... how can I tell R to
leave
> this row as NA, as below?
>
> [1] 17.0 1.1
>
> [2] 15.2 NA
>
>
>
> [3] 17.3 3.8
>
>
>
> [4] 15.0 1.3
>
>
> [5] 17.4 0.9
> thanks and greets.
> Arantzazu Blanco Bernardeau
> Dpto de Química Agrícola, Geología y Edafología
> Universidad de Murcia-Campus de Espinardo
>
> _________________________________________________________________
> ¿Un navegador seguro buscando estás? ¡Protegete ya en
www.ayudartepodria.com!
> www.ayudartepodria.com
> ______________________________________________
> 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.



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. Received on Thu 10 Jun 2010 - 08:54:57 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 10 Jun 2010 - 09:00:30 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive