0

## 如何使用R語言使數值重複出現?

⠀戶內人口數⠀⠀⠀個人可支配所得
⠀⠀⠀1⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀100
⠀⠀⠀⠀3⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀200
⠀⠀⠀⠀1⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀300
⠀⠀⠀⠀2⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀400
⠀⠀⠀⠀1⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀500

100,
200,
200,
200,
300,
400,
400,
500呢?

20191205 16:41 更

(-68970,-66995,-5884,-4339,-4339,2839.5.....)

marlin12 iT邦研究生 5 級 ‧ 2019-12-05 19:12:53 檢舉
df <- data.frame(

)

cat( rep( df\$個人可支配所得, df\$戶內人口數 ), sep=",\n" )

### 1 個回答

1

iT邦大神 1 級 ‧ 2019-12-05 15:36:16

R 皮 C 骨的答案

``````population <- c(1, 1, 1, 2, 2, 3)
income <- c(-68970.00, -66995.00, -5884, -4339, 2839.50, 28365.00)
for (i in c(1:length(population))) {
for (j in c(1:population[c(i)])) {
if ((i==1)&(j==1)) {
} else {
cat(",")
}
cat(income[c(i)])
}
}
``````

``````population <- c(1, 1, 1, 2, 2, 3)
income <- c(-68970.00, -66995.00, -5884, -4339, 2839.50, 28365.00)
for (i in c(1:length(population))) {
for (j in c(1:population[c(i)])) {
if ((i==length(population))&(j==population[c(i)])) {
comma <- "呢?"
} else {
comma <- ","
}
cat(sprintf("%.1f%s\n",income[c(i)],comma))
}
}
``````

C IS GOOOOOOOOOOOOOOOD