[R] Double Roop

Peter Maclean pmaclean2011 at yahoo.com
Tue Jun 30 15:04:36 CEST 2015


 Hi EverybodyI am trying to make an object with  length(a) * length(b) element using a double loop. But I am getting the last part only.  A simple script is
a <- c("A-AA", "B-BB", "C-CC")
b    <- seq(1, 5)
pre <- NULL
post <- NULL
page <- NULLfor(j in 1:length(a)) {
   for(i in 1:length(b)){
       pre[j]  <- strsplit(a[j],"-")[[1]][1] 
          post[j] <- strsplit(a[j],"-")[[1]][2] 
            page[i] <- paste0(pre[j], b[i],post[j])  
}}Peter Maclean
Department of Economics
UDSM
	[[alternative HTML version deleted]]



More information about the R-help mailing list