不要有因爲結構,但一個非常優雅的方式動物園:: na.locf可能是你在找什麼
library(zoo)
data <- structure(list(V1 = structure(c(3L, 1L, 1L, 2L), .Label = c("",
"EEA", "Region"), class = "factor"), V2 = structure(c(3L, 1L,
1L, 2L), .Label = c("", "Austria", "Sender"), class = "factor"),
V3 = structure(c(3L, 2L, 4L, 1L), .Label = c("165", "Adult",
"Afghanistan", "Male "), class = "factor"), V4 = structure(c(1L,
1L, 3L, 2L), .Label = c("", "8", "Female"), class = "factor"),
V5 = structure(c(1L, 4L, 3L, 2L), .Label = c("", "6", "Male",
"Minor"), class = "factor"), V6 = structure(c(1L, 1L, 3L,
2L), .Label = c("", "10", "Female"), class = "factor")), .Names = c("V1",
data[1:3,][data[1:3,]==""] <- NA
data <- na.locf(zoo(data), fromLast=F)
df <- cbind(as.character(data$V1[4]), as.character(temp$V2[4]),
data.frame(na.locf(zoo(t(data)), fromLast=F)[-(1:2),]))
setNames(df, c("Reg","Send","Rec","Age","Gender", "Value"))
是第一臺CSV文件?你可以用逗號粘貼它嗎? – chinsoon12
對不起,它在評論部分 – chinsoon12
不是很可讀!你是對的!我改變了原來的代碼。 – Thomas