Hi,
I have a vector of Size 7420. I wanna break down in such a way that every 20
elements of it should be as elements of an list.
Ex
EXAM1
ABC, SDF, LMN,ERF,EGC,EFG,WER,FRE,QWE,ERT,DGW,QWE,YUR,ERT,GHJ,FHH,....7420
what i want is
Breakdown.list
[[1]]
ABC,SDF,.....20
[[2]]
21.....40
[[3]]
41....50
i thought of using a for loop but i am wondering how to incerment
test.breakdown.list<-list()
for( i =0;i<=length(EXAM1);i+20)
{
test.breakdown.list<-Exam1[c(i:i+20)]
print (paste(i))
}
Ias this how we do...please correct me if am wrong.
Regards
Ramya
--
View this message in context:
http://www.nabble.com/Breakdown-of-Vector-tp20623764p20623764.html
Sent from the R help mailing list archive at Nabble.com.
No need to use a for loop. Try something like this
dim(EXAM1) <- c(20,7420/20)
test.breakdown.list <- as.list(data.frame(EXAM1))
-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org]
On Behalf Of Rajasekaramya
Sent: Friday, November 21, 2008 9:48 AM
To: r-help at r-project.org
Subject: [R] Breakdown of Vector
Hi,
I have a vector of Size 7420. I wanna break down in such a way that
every 20 elements of it should be as elements of an list.
Ex
EXAM1
ABC, SDF,
LMN,ERF,EGC,EFG,WER,FRE,QWE,ERT,DGW,QWE,YUR,ERT,GHJ,FHH,....7420
what i want is
Breakdown.list
[[1]]
ABC,SDF,.....20
[[2]]
21.....40
[[3]]
41....50
i thought of using a for loop but i am wondering how to incerment
test.breakdown.list<-list()
for( i =0;i<=length(EXAM1);i+20)
{
test.breakdown.list<-Exam1[c(i:i+20)]
print (paste(i))
}
Ias this how we do...please correct me if am wrong.
Regards
Ramya
--
View this message in context:
http://www.nabble.com/Breakdown-of-Vector-tp20623764p20623764.html
Sent from the R help mailing list archive at Nabble.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.
Also something along the following lines:> x <- 1:100 > y <- split(x, (seq(along = x) - 1) %/% 5)HTH, Giovanni Petris> Date: Fri, 21 Nov 2008 07:48:09 -0800 (PST) > From: Rajasekaramya <ramya.victory at gmail.com> > Sender: r-help-bounces at r-project.org > Precedence: list > > > Hi, > > I have a vector of Size 7420. I wanna break down in such a way that every 20 > elements of it should be as elements of an list. > > Ex > EXAM1 > ABC, SDF, LMN,ERF,EGC,EFG,WER,FRE,QWE,ERT,DGW,QWE,YUR,ERT,GHJ,FHH,....7420 > > what i want is > Breakdown.list > [[1]] > ABC,SDF,.....20 > [[2]] > 21.....40 > [[3]] > 41....50 > > i thought of using a for loop but i am wondering how to incerment > test.breakdown.list<-list() > for( i =0;i<=length(EXAM1);i+20) > { > test.breakdown.list<-Exam1[c(i:i+20)] > print (paste(i)) > } > > Ias this how we do...please correct me if am wrong. > > Regards > Ramya > > > -- > View this message in context: http://www.nabble.com/Breakdown-of-Vector-tp20623764p20623764.html > Sent from the R help mailing list archive at Nabble.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. > >-- Giovanni Petris <GPetris at uark.edu> Associate Professor Department of Mathematical Sciences University of Arkansas - Fayetteville, AR 72701 Ph: (479) 575-6324, 575-8630 (fax) http://definetti.uark.edu/~gpetris/
another way: exam.list <- split(EXAM, floor((seq_along(EXAM) - 1) / 20)) On Fri, Nov 21, 2008 at 10:48 AM, Rajasekaramya <ramya.victory at gmail.com> wrote:> > Hi, > > I have a vector of Size 7420. I wanna break down in such a way that every 20 > elements of it should be as elements of an list. > > Ex > EXAM1 > ABC, SDF, LMN,ERF,EGC,EFG,WER,FRE,QWE,ERT,DGW,QWE,YUR,ERT,GHJ,FHH,....7420 > > what i want is > Breakdown.list > [[1]] > ABC,SDF,.....20 > [[2]] > 21.....40 > [[3]] > 41....50 > > i thought of using a for loop but i am wondering how to incerment > test.breakdown.list<-list() > for( i =0;i<=length(EXAM1);i+20) > { > test.breakdown.list<-Exam1[c(i:i+20)] > print (paste(i)) > } > > Ias this how we do...please correct me if am wrong. > > Regards > Ramya > > > -- > View this message in context: http://www.nabble.com/Breakdown-of-Vector-tp20623764p20623764.html > Sent from the R help mailing list archive at Nabble.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. >-- Jim Holtman Cincinnati, OH +1 513 646 9390 What is the problem that you are trying to solve?