2013-06-03 3 views
0

입니다. 몇 가지 데이터 프레임이 있으며이 데이터를 추가하려고합니다. 다음과 같이 재생 가능한 예는 다음과 같습니다데이터를 추가하는 효율적인 방법은 R

new <- c("data", "up") 
new0 <- append(new,coordgous) 
new1 <- append(new0,c(t(gous)),after=length(new0)) 
new2 <- append(new1,"MZ",after=length(new1)) 
new3 <- append(new2,coordgomz,after=length(new2)) 
new4<- append(new3,c(t(gomz)),after=length(new3)) 
new5 <- append(new4,"ARI",after=length(new4)) 
new6 <- append(new5,coordari,after=length(new5)) 
new7 <- append(new6,c(t(ari)),after=length(new6)) 
new8 <- append(new7,"DS",after=length(new7)) 
new9 <- append(new8,coordgods,after=length(new8)) 
new10 <- append(new9, c(t(gods)), after=length(new9)) 

내가 완벽하게 작품을 사용하지만, 효율적인 하나가 될 것 같지 않습니다 방법 :

gous <- structure(list(V1 = c(0, 28.44), V2 = c(1, 28.44), V3 = c(2, 
28.44), V4 = c(3, 28.39), V5 = c(4, 28.22), V6 = c(5, 27.72), 
    V7 = c(6, 24.56), V8 = c(7, 18.78), V9 = c(8, 18.5), V10 = c(9, 
    18.56), V11 = c(10, 18.5), V12 = c(11, 18.72)), .Names = c("V1", 
"V2", "V3", "V4", "V5", "V6", "V7", "V8", "V9", "V10", "V11", 
"V12"), class = "data.frame", row.names = c(NA, -2L)) 

gous1<- structure(list(V1 = structure(1L, .Label = "GOUS,", class = "factor"), 
    V2 = 479868.2, V3 = 3723003.3), .Names = c("V1", "V2", "V3" 
), class = "data.frame", row.names = c(NA, -1L)) 

coordgous <- paste0(gous1$V2,",",gous1$V3) 
gomz <-  structure(list(V1 = c(0, 29.28), V2 = c(1, 29.22), V3 = c(2, 
29.11), V4 = c(3, 28.94), V5 = c(4, 28.44), V6 = c(5, 27.61), 
    V7 = c(6, 26.89), V8 = c(7, 25.22), V9 = c(8, 23.56), V10 = c(9, 
    22.72), V11 = c(10, 22.44), V12 = c(11, 22.28)), .Names = c("V1", 
"V2", "V3", "V4", "V5", "V6", "V7", "V8", "V9", "V10", "V11", 
"V12"), class = "data.frame", row.names = c(NA, -2L)) 

gomz1 <- structure(list(V1 = structure(1L, .Label = "Mixing", class = "factor"), 
    V2 = structure(1L, .Label = "Zone,", class = "factor"), V3 = 479868.2, 
    V4 = 3723003.3), .Names = c("V1", "V2", "V3", "V4"), class = "data.frame", row.names = c(NA, 
-1L)) 

coordgomz <- paste0(gomz1$V3,",",gomz1$V4) 

ari <- structure(list(V1 = c(0, 29.22), V2 = c(1, 29.17), V3 = c(2, 
29.11), V4 = c(3, 28.83), V5 = c(4, 28.28), V6 = c(5, 27.5), 
    V7 = c(6, 26.17), V8 = c(7, 19.89), V9 = c(8, 20.11)), .Names = c("V1", 
"V2", "V3", "V4", "V5", "V6", "V7", "V8", "V9"), class = "data.frame", row.names = c(NA, 
-2L)) 

ari1 <- structure(list(V1 = structure(1L, .Label = "AboveRiverIntake,", class = "factor"), 
    V2 = 482631.6, V3 = 3722791.3), .Names = c("V1", "V2", "V3" 
), class = "data.frame", row.names = c(NA, -1L)) 

coordari <- paste0(ari1$V2,",",ari1$V3) 

gods <- structure(list(V1 = c(0, 28.61), V2 = c(1, 28.56), V3 = c(2, 
28.56), V4 = c(3, 28.5), V5 = c(4, 28.06), V6 = c(5, 27.83), 
    V7 = c(6, 27.56), V8 = c(7, 27.44), V9 = c(8, 26.17), V10 = c(9, 
    25.17)), .Names = c("V1", "V2", "V3", "V4", "V5", "V6", "V7", 
"V8", "V9", "V10"), class = "data.frame", row.names = c(NA, -2L 
)) 

gods1 <- structure(list(V1 = structure(1L, .Label = "Downstream,", class = "factor"), 
    V2 = 480553.1, V3 = 3720785), .Names = c("V1", "V2", "V3" 
), class = "data.frame", row.names = c(NA, -1L)) 

coordgods <- paste0(gods1$V2,",",gods1$V3) 

코드는 내가 다음과 같이 데이터가 추가하는 데 사용됩니다. 이렇게하는 효율적인 방법이 있어야합니다.

> print(new10,quote=F) 
[1] data    up     479868.2,3723003.3 0     1     2     3     
[8] 4     5     6     7     8     9     10     
[15] 11     28.44    28.44    28.44    28.39    28.22    27.72    
[22] 24.56    18.78    18.5    18.56    18.5    18.72    MZ     
[29] 479868.2,3723003.3 0     1     2     3     4     5     
[36] 6     7     8     9     10     11     29.28    
[43] 29.22    29.11    28.94    28.44    27.61    26.89    25.22    
[50] 23.56    22.72    22.44    22.28    ARI    482631.6,3722791.3 0     
[57] 1     2     3     4     5     6     7     
[64] 8     29.22    29.17    29.11    28.83    28.28    27.5    
[71] 26.17    19.89    20.11    DS     480553.1,3720785 0     1     
[78] 2     3     4     5     6     7     8     
[85] 9     28.61    28.56    28.56    28.5    28.06    27.83    
[92] 27.56    27.44    26.17    25.17 
+0

그냥 한 줄에'c '(데이터', '위로', coordgous, c (t (gous)), ...)' – eddi

답변

1

그냥 c로 한 번에 모든 것을 할 : 다음과 같이

원하는 최종 출력이다. (원래 코드에서 거기에 남아있는 일부 무상 c 전화)

new10 <- c("data", "up", coordgous,c(t(gous)),"MZ",coordgomz,c(t(gomz)),"ARI",coordari,c(t(ari)),"DS",coordgods,c(t(gods))) 

+0

감사합니다. 왜 그런지 모르겠습니다. 그것을 시도해보십시오 –

3

나는이 전략으로 정보를 잃어 버리고 있다는 느낌을 가지고 있습니다. 네 세트의 데이터가 있습니다.

다음
newdat <- list(US = list(coordgous, t(gous)), 
       MZ = list(coordgomz, t(gomz)), 
       ARI = list(coordari, t(ari)) 
       DS = list(coordgods, t(gods))) 

할 수 있습니다 중 하나 "lapply"이름으로 각 항목에 "

> cords <- sapply(newdat, "[", 1) 
> cords 
$US 
[1] "479868.2,3723003.3" 

$MZ 
[1] "479868.2,3723003.3" 

$ARI 
[1] "482631.6,3722791.3" 

$DS 
[1] "480553.1,3720785" 

... 또는 기준 이상 :

newdat[["US"]] 
#--------- 
$US 
$US[[1]] 
[1] "479868.2,3723003.3" 

$US[[2]] 
    [,1] [,2] 
V1  0 28.44 
V2  1 28.44 
V3  2 28.44 
V4  3 28.39 
V5  4 28.22 
V6  5 27.72 
V7  6 24.56 
V8  7 18.78 
V9  8 18.50 
V10 9 18.56 
V11 10 18.50 
V12 11 18.72 
이 이름으로 그룹에 데이터를 더 적합 할 수 있습니다
+0

+1 Dwin, 귀하의 제안에 감사드립니다. 네, dat 당신이 제안한대로. –

+0

다른 게시물에서 @Dason을 인용하려면 다음과 같이하십시오. "_ 더 나은 방법이 있음을 보장합니다. 목록을 사용하는 것이 가장 가능성이 있습니다. 항상 목록 사용 _ – thelatemail

관련 문제