LISTSERV mailing list manager LISTSERV 16.0

Help for R-USERS-L Archives


R-USERS-L Archives

R-USERS-L Archives


R-USERS-L@LISTS.UFL.EDU


View:

Message:

[

First

|

Previous

|

Next

|

Last

]

By Topic:

[

First

|

Previous

|

Next

|

Last

]

By Author:

[

First

|

Previous

|

Next

|

Last

]

Font:

Proportional Font

LISTSERV Archives

LISTSERV Archives

R-USERS-L Home

R-USERS-L Home

R-USERS-L  2018

R-USERS-L 2018

Subject:

Re: How to create loop of different sequence for each record

From:

"Bruna, Emilio M." <[log in to unmask]>

Reply-To:

UF R Users List <[log in to unmask]>

Date:

Tue, 22 May 2018 14:12:04 +0000

Content-Type:

text/plain

Parts/Attachments:

Parts/Attachments

text/plain (1 lines)

Hi Pornpamol,

I may have misunderstood, and I couldn’t run your code snippet because we are missing `sam_10tdw`,  but I think the goal is for each animal to have a number in this format:

1305
2305
3305
4305
5305
….
….
199305
200305

Why not generate the sequence first, then append 305 to the number in a second step?

foo<-sequence(200)
foo<-as.numeric(paste(foo,"305", sep=""))
foo<-as.data.frame(foo)


or in your case (I think):

foo<-sequence(nrow(sam_10tdw))
foo<-as.numeric(paste(foo,"305", sep=""))
foo<-as.data.frame(foo)

EB

From: "[log in to unmask]" <[log in to unmask]> on behalf of "Pattamanont,Pornpamol" <[log in to unmask]>
Reply-To: "[log in to unmask]" <[log in to unmask]>
Date: Tuesday, May 22, 2018 at 9:46 AM
To: "[log in to unmask]" <[log in to unmask]>
Subject: How to create loop of different sequence for each record

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 http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Top of Message | Previous Page | Permalink

Advanced Options


Options

Log In

Log In

Get Password

Get Password


Search Archives

Search Archives


Subscribe or Unsubscribe

Subscribe or Unsubscribe


Archives

2019
2018
2017
2016
2015
2014
2013
2012
2011
2010
2009
2008

ATOM RSS1 RSS2



LISTS.UFL.EDU

CataList Email List Search Powered by the LISTSERV Email List Manager