Hola, Esta es una forma:
#---------------------------------------------- Lines <-" X Y Z W 35 25 S 20 35 25 S 18 35 27 N 18 40 20 S 15 40 15 S 18 20 19 S 10 20 18 N 15 30 20 N 10 " DF <- read.table(textConnection(Lines), as.is = TRUE, header = TRUE) DF_re <- reshape(DF, idvar="X", timevar=2:4, direction="wide") col_n <- c('Y','Z','W') col_ext <- expand.grid(col_n, seq(1:3)) col_end <- paste(col_ext$Var1, col_ext$Var2, sep=".") names(DF_re) <- c(names(DF_re)[1], col_end) n_nam <- sort(names(DF_re)[2:ncol(DF_re)]) sr_DFn <- DF_re[, n_nam] DF_end <- cbind(DF_re[,1], sr_DFn) names(DF_end)[1] <- "X" DF_end[ is.na(DF_end)] <- c("-") #---------------------------------------------- Saludos, Carlos Ortega www.qualityexcellence.es El 6 de diciembre de 2016, 0:35, franz condori <fra.ger...@gmail.com> escribió: > Hola a todos.tengo un problema al estructurar un a base, quiero agrupar la > base por la variable X y luego desagregar las variables Y, Z y W en todas > las variables posibles, > > Ejemplo: > > X. Y. Z. W. > 35. 25. S. 20 > 35. 25. S 18 > 35. 27. N. 18 > 40. 20. S. 15 > 40. 15. S. 18 > 20. 19. S. 10 > 20. 18. N 15 > 30. 20. N. 10 > > Transformar a los siguiente > > X Y1 Y2. Y3. Z1. Z2. Z3 W1 W2. W3 > 35 25 25 27 S S N. 20 18. 18 > 40.20 15. 'S. S. 15. 18 > 20 19 18. S. N. 10. 15. > 30 20. N. 18 > > Espero entiendan mi ejemplo, si existe alguna librería para realizar el > procedimiento les agradecería que me lo escriban o si se puede hacer de > forma manual, como lo haría. > > Gracias por todo > > Franz > > [[alternative HTML version deleted]] > > _______________________________________________ > R-help-es mailing list > R-help-es@r-project.org > https://stat.ethz.ch/mailman/listinfo/r-help-es > -- Saludos, Carlos Ortega www.qualityexcellence.es [[alternative HTML version deleted]] _______________________________________________ R-help-es mailing list R-help-es@r-project.org https://stat.ethz.ch/mailman/listinfo/r-help-es