Thanks guys,
I want the sequences start from the particular number of each record until 305 (i.e. 40, 41, 42, ..., 305). Each record starts with the different number.
Using list is interesting, but I have a tough time extracting the result from list. I attached my code and data, just in case you want to try running with the data.
I'll try what you guys suggested.
________________________________
From: UF R Users List <[log in to unmask]> on behalf of Hao Ye <[log in to unmask]>
Sent: Tuesday, May 22, 2018 10:46:47 AM
To: [log in to unmask]
Subject: Re: How to create loop of different sequence for each record
Hi Pornpamol,
A couple of things I noticed here:
(1) In R, a matrix and a data.frame are always rectangular, so both the
number of rows is fixed, as well as the number of columns. If you want a
more generic structure to store sequences of different lengths, you might
be looking for a list:
```
E_table < list(300:305, 290:305)
E_table[[1]] # is the sequence 300:305
E_table[[2]] # is the sequence 290:305
# note the use of double square brackets to extract out the contents of the
list
```
(2) It looks like `sam_10tdw` is a data.frame or matrix, so
`sam_10tdw$dimEW` will return a vector of values. If you want to access
this for each individual row, using the index variable `i`, then you
probably want `sam_10tdw$dimEW[i]`.
Best,

Hao Ye
[log in to unmask]
On Tue, May 22, 2018 at 9:46 AM, Pattamanont,Pornpamol <[log in to unmask]
> wrote:
> Hello guys,
>
>
> I'm trying to create a sequence of number for each cow. The starting
> numbers are different by each. The final number is the same which is 305.
> My questions are:
>
>
> Question1. How can I create a sequence of number for each cows by loop?
>
>
> E_table < matrix(NA,nrow = nrow(sam_10tdw), ncol = 268, byrow = T)
> for(i in 1:nrow(sam_10tdw)) {
> nE < sam_10tdw[i,c(sam_10tdw$dimEW:305)]
> E_table[i,] < nE
> }
>
> E_table < matrix(NA,nrow = nrow(sam_10tdw), ncol = 268, byrow = T)
> for(i in 1:nrow(sam_10tdw)) {
> nE < seq(sam_10tdw$dimEW, 305, by = 1)
> E_table[i,] < nE
> }
>
> These 2 codes didn't work. (using only "nE < c(sam_10tdw$dimEW:305)" is
> work for 1 cow)
>
> Question2. How can I create matrix to store these sequences which
> have different columns for each cow. The shortest column length is 145
> columns; the longest is 268 columns. I try to assign the longest columns,
> but not sure if it works as I stuck with an error from question 1.
>
> Thanks for your help (Hopefully I wrote it clear enough),
> Pornpamol
>
> This list strives to be beginner friendly. However, we still ask that you
> PLEASE do read the posting guide https://urldefense.proofpoint.com/v2/url?u=http3A__www.R2Dproject.org_&d=DwIBaQ&c=pZJPUDQ3SB9JplYbifm4nt2lEVG5pWx2KikqINpWlZM&r=QWxQId63qB2iSP1ggUL7kQsdfEWUTu6qCGEw8Xuo91A&m=cjc_yWmvWTsVBqb2dmBg1IzJGbHGpksdKi5dpx5xdY&s=wfmHG_V2lecw65_DVoCNds6capgQYLdHj5fbPhTA9yY&e=
> postingguide.html
> and provide commented, minimal, selfcontained, reproducible code.
>
This list strives to be beginner friendly. However, we still ask that you
PLEASE do read the posting guide http://www.Rproject.org/postingguide.html
and provide commented, minimal, selfcontained, reproducible code.
This list strives to be beginner friendly. However, we still ask that you
PLEASE do read the posting guide http://www.Rproject.org/postingguide.html
and provide commented, minimal, selfcontained, reproducible code.
