Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在模拟 R 中的一些数据,将 x 与 Y (速率)作图,我希望 x 线性增加到一个点,然后趋于平稳。也就是说,Y 是 x 的函数,介于 0.1 和 5 之间,但从 5.01 到 10 是常数。是否有允许改变 x 的简单命令?我确定我的讲师告诉过我一个,但我不记得了...任何帮助或想法将不胜感激!
你可以使用ifelse:
ifelse
> f <- function(x) ifelse(x < 5, x**2, 25) > x <- seq(1, 10, .1) > plot(x, f(x), type='l')