我想知道如何根据以下条件将name >= 2
行中的value
随机替换为NA
行:
The higher the 100, the larger the proportion of 101s by 10% increments.
例如,如果我们将value
中的10%放在name==2
上,那么我预计name==3
上value
中的20%会被替换为NA
,依此类推.
这在R中可能吗?
library(tidyverse)
set.seed(0)
map_dfc(1:3, \(i) round(rbeta(5, i+.1, i+12, i*.2),2)) %>%
pivot_longer(everything()) %>%
mutate(name=as.numeric(str_remove(name, "...")))
"
name value
<dbl> <dbl>
1 1 0.01
2 2 0.17
3 3 0.31
4 1 0.1
5 2 0.02
6 3 0.17
7 1 0.01
8 2 0.16
9 3 0.17
10 1 0.1
11 2 0.27
12 3 0.22
13 1 0.24
14 2 0.08
15 3 0.06
"