找到最不常见的乘数将数字向量转换为整数 我有以下矢量。 vector_1

问题描述 投票:0回答:1
完成此任务的最佳方法是什么?

,例如,向量

c(0.5, (1 / 3), (2 / 7))
可以乘以
42

2 * 3 * 7

)以使矢量

c(21, 14, 12)

。 thanks!

    
given
v <- c(0.1, 0.9, 0.5, (1 / 3), 0.5344)
,一种天真的解决方案正在使用
repeat

d <- 1 repeat { if (all((v * d) %% 1 == 0)) { break } d <- d + 1 }

r integer decimal multiplication fractions
1个回答
0
投票

> d [1] 3750

    

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.