Wow - thanks a lot for your help. Sorry it's taken a while to answer, but honestly, didn't expect a reply so soon. Sorry I hadn't provided enough information at the beginning, but you'd correctly figured it was a csv file (actually exported from Excel). I had figured that there was a more streamlined way to do what I was trying to do, so will study the code you provided. Thanks again,

MH

Date: Sun, 14 Apr 2013 14:06:41 -0700
From: ml-node+s789695n4664202h94@n4.nabble.com
To: noyfb555@hotmail.com
Subject: Re: possible loop problem



	

Hi,

It would be better if you provided the output of dput(dataset).  I am not sure about the structure of your dataset.


Just from reading the data as is shown.

dat1<- read.table(text="

separator,tissID

>,>,2

,2,1

,6,5

,11,13

>,>,4

,4,9

,6,2

,7,3

,21,1

,23,58

,25,9

,26,4

>,>,11

,1,12

>,>,21

,4,1

,11,3

",sep=",",header=TRUE,stringsAsFactors=FALSE,row.names=NULL) 

indx<-which(grepl(">",dat1[,1]))

indx1<-diff(c(indx,nrow(dat1)+1))


res1<-do.call(rbind,lapply(seq_along(indx),function(i) {x1<-dat1[indx[i]:(indx[i]+(indx1[i]-1)),];x1[-1,1]<- x1[1,3];x1}))

res2<- as.matrix(res1[,-1])

row.names(res2)<- res1[,1] 

 res2

#   separator tissID

#>  ">"       " 2"  

#2  "2"       " 1"  

#2  "6"       " 5"  

#2  "11"      "13"  

#>  ">"       " 4"  

#4  "4"       " 9"  

#4  "6"       " 2"  

#4  "7"       " 3"  

#4  "21"      " 1"  

#4  "23"      "58"  

#4  "25"      " 9"  

#4  "26"      " 4"  

#>  ">"       "11"  

#11 "1"       "12"  

#>  ">"       "21"  

#21 "4"       " 1"  

#21 "11"      " 3"  


A.K.



 		 	   		  



--
View this message in context: http://r.789695.n4.nabble.com/possible-loop-problem-tp4664146p4664799.html
Sent from the R help mailing list archive at Nabble.com.
	[[alternative HTML version deleted]]

