0
에 다음 열에서 값이 일치하는 대체 방법 :나는 데이터 프레임이 R
structure(list(City = structure(c(4L, 2L, 1L, 3L, 3L, 3L), .Label = c("Gold Cost",
"Melbourne", "Other", "Sydney"), class = "factor"), Town = structure(c(1L,
1L, 1L, 3L, 4L, 2L), .Label = c("", "Brighton", "Hurstville",
"Penhurst"), class = "factor")), .Names = c("City", "Town"), class = "data.frame", row.names = c(NA,
-6L))
내가 값을 다른 이름을 지정하고 다음 열에서 값으로 교체 포함 열라는 이름의 도시에서 모든 행을 대체 할을 동일한 행의
내 출력은, 다음과 같이
structure(list(City = structure(c(6L, 4L, 2L, 3L, 5L, 1L), .Label = c("Brighton",
"Gold Cost", "Hurstville", "Melbourne", "Penhurst", "Sydney"), class = "factor"),
Town = structure(c(1L, 1L, 1L, 3L, 4L, 2L), .Label = c("",
"Brighton", "Hurstville", "Penhurst"), class = "factor")), .Names = c("City",
"Town"), class = "data.frame", row.names = c(NA, -6L))
내가 전에 어떤 기능을 작성하지 않은하지만 난 그게 다음과 같아야합니다 추측하고있다 :
for(data1 in 1:nrow(data1)) {
if(data1$City[i] == 'Other') {
data1$city[i] <- data1$Town[i]
} else {
break
}
}
- 내가 잘못 어디 갔지 ?
- 앞으로 이와 같은 문제를 해결하기 위해서는 어떻게 생각해야할까요?
- 원하는 결과를 얻으려면 어떻게해야합니까?
아하! 도와 줘서 고맙습니다. @ Hack-R. – Chemjong