Hi R-users,
   
  I have a matrice called layout which contains 5 columns:id, name, row, column 
and block. The column called "block" has totally 48 blocks and looks like
   
   
  1  2   3  4
  5  6  7  8
  9 10 11 12
  13 14 15 16
  17 18 19 20
  21 22 23 24
  25 26 27 28 
  29 30 31 32
  33 34 35 36
  37 38 39 40
  41 42 43 44 
  45 46 47 48
   
  Each block (1-48) has 18 rows and 18 columns. I want to create 2 variables 
called blockrow and blockcol in such a way that blockrow will have value 1 for 
block 1,2 3 and 4, blockrow=2 for blocks 5,6,7 and 8 and so on. Similarly, 
blockcol = 1 for blocks 1,5 ,9,13,17,21,25,29,33,37,41 and 44 and so on. As you 
can see there are 12 blockrows and 4 blockcols. I have written the following 
programme but it didnot give the desirable output. How can I make it work in a 
simplier way ?
   
  # five first columns give position identifiers
layout=a[,1:5]

#---------- Append some more columns to the identifiers----------------------


blockrow<-rep(0,nrow(layout))
blockcol<-rep(0,nrow(layout))
blockrow[layout$Block==c("1","2","3","4")]=1
blockrow[layout$Block==c("5","6","7","8")]=2
blockrow[layout$Block==c("9","10","11","12")]=3
blockrow[layout$Block==c("13","14","15","16")]=4
blockrow[layout$Block==c("17","18","19","20")]=5
blockrow[layout$Block==c("21","22","23","24")]=6
blockrow[layout$Block==c("25","26","27","28")]=7
blockrow[layout$Block==c("29","30","31","32")]=8
blockrow[layout$Block==c("33","34","35","36")]=9
blockrow[layout$Block==c("37","38","39","40")]=10
blockrow[layout$Block==c("41","42","43","44")]=11
blockrow[layout$Block==c("45","46","47","48")]=12
blockcol[layout$Block==c("1","5","9","13","17","21","25","29","33","37","41","45")]=1
blockcol[layout$Block==c("2","6","10","14","18","22","26","30","34","38","42","46")]=2
blockcol[layout$Block==c("3","7","11","15","19","23","27","31","35","39","43","47")]=3
slidecol[layout$Block==c("4","8","12","16","20","24","28","32","36","40","44","48")]=4


   
  #---------- re-arrange the response (index) as a long vector and the
#   layout matrix as a long matrix matching the response vector
  y=c(index)
   
   
  layout=data.frame(layout, Control,blockow,blockcol)
Block=as.factor(rep(layout$Block, ncol(index)))
Column=rep(layout$Column, ncol(index))
Row=rep(layout$Row, ncol(index))
Name=as.factor(rep(layout$Name, ncol(index)))
ID=rep(layout$ID, ncol(index))
blockrow=rep(layout$sliderow, ncol(index))
blockcol=rep(layout$slidecol, ncol(index))

Thanks for your help,
   
  Best regards,
  Jenny

        [[alternative HTML version deleted]]

______________________________________________
[email protected] 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.

Reply via email to