# [R] arrange data for simple regression analysis

Gabor Grothendieck ggrothendieck at gmail.com
Mon Apr 24 12:39:13 CEST 2006

```Here are a couple of possibilities using the builtin iris data set.  Note
that although the coefficients come out the same, the degrees of
freedom, etc., would differ:

> n <- rep(1:3, 50)
> lm(Petal.Length ~ Petal.Width, iris, weight = n)

Call:
lm(formula = Petal.Length ~ Petal.Width, data = iris, weights = n)

Coefficients:
(Intercept)  Petal.Width
1.057        2.262

> lm(Petal.Length ~ Petal.Width, iris[rep(1:nrow(iris), n),])

Call:
lm(formula = Petal.Length ~ Petal.Width, data = iris[rep(1:nrow(iris),
n), ])

Coefficients:
(Intercept)  Petal.Width
1.057        2.262

On 4/24/06, Tomás Revilla <tomlists at gmail.com> wrote:
> Hello, I want to arrange data from a table to perform a simple
> regression. All the examples I saw deal with paired data, e.g. 'x' and
> 'y' have the same dimensions (e.g. 5 values for x and 5 for y).
>
> But I have more than one 'y' for each 'x' value, e.g. the data file
> has a x = 0, 30, 60, and 120 columns. And for each of them I have
> several replicate responses (e.g. individuals), not allways the same
> number. After I read the data with read.table(), ending with 4
> columns, what is next? how can I regress this against c(0, 30, 60,
> 120)?
>
> 0       -->   n1 y values
> 30     -->  n2 y values
> 60     --> n3 y values
> 120  --> n4 y values
>
> Thanks,
>
> Tomas
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help