我正在尝试在R中创建一个循环,将第1年的结果合并到第2年等的计算中,该循环将运行10个阶段(例如10年)。我确信这应该很容易做到,但是我不知道这种计算类型是否具有特定名称,所以我不知道要搜索什么。
所以我基本上是去做一些可以做的事情:
(a*1.5)-(b*4)=c
(c*1.5)-(b*4)=d
(d*1.5)-(b*4)=e
等... 直到获得第十阶段的结果,然后将其全部组织为一个方程式
答案 0 :(得分:0)
您正在做的事情简称为迭代计算。您可以这样:
"I/O Queue" #19 prio=5 os_prio=31 tid=0x00007ffe3d85a000 nid=0x12007 runnable [0x0000700004822000]
java.lang.Thread.State: RUNNABLE
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1941)
- locked <0x000000076ab068a8> (a java.util.Vector)
- locked <0x000000076ab06900> (a java.util.Vector)
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1824)
at java.lang.Runtime.load0(Runtime.java:809)
- locked <0x000000076ab1dea8> (a java.lang.Runtime)
at java.lang.System.load(System.java:1086)
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1941)
- locked <0x000000076ab068a8> (a java.util.Vector)
- locked <0x000000076ab06900> (a java.util.Vector)
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1845)
at java.lang.Runtime.loadLibrary0(Runtime.java:870)
- locked <0x000000076ab1dea8> (a java.lang.Runtime)
at java.lang.System.loadLibrary(System.java:1122)
at java.awt.Toolkit$3.run(Toolkit.java:1636)
at java.awt.Toolkit$3.run(Toolkit.java:1634)
at java.security.AccessController.doPrivileged(Native Method)
at java.awt.Toolkit.loadLibraries(Toolkit.java:1633)
at java.awt.Toolkit.<clinit>(Toolkit.java:1670)
at sun.awt.AppContext$2.run(AppContext.java:277)
at sun.awt.AppContext$2.run(AppContext.java:266)
at java.security.AccessController.doPrivileged(Native Method)
at sun.awt.AppContext.initMainAppContext(AppContext.java:266)
at sun.awt.AppContext.access$400(AppContext.java:135)
at sun.awt.AppContext$3.run(AppContext.java:321)
- locked <0x000000076c238c00> (a sun.awt.AppContext$GetAppContextLock)
at sun.awt.AppContext$3.run(AppContext.java:304)
at java.security.AccessController.doPrivileged(Native Method)
at sun.awt.AppContext.getAppContext(AppContext.java:303)
at javax.imageio.spi.IIORegistry.getDefaultInstance(IIORegistry.java:154)
at javax.imageio.ImageIO.<clinit>(ImageIO.java:66)
at com.example.SeparateThreadAsync.getIcon(SeparateThreadAsync.java:49)
at com.example.SeparateThreadAsync.lambda$start$2(SeparateThreadAsync.java:33)
at com.example.SeparateThreadAsync$$Lambda$61/1820086024.run(Unknown Source)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
"JavaFX Application Thread" #15 prio=5 os_prio=31 tid=0x00007ffe3b0e4000 nid=0x307 waiting for monitor entry [0x00007ffee75f1000]
java.lang.Thread.State: BLOCKED (on object monitor)
at java.lang.Runtime.load0(Runtime.java:801)
- waiting to lock <0x000000076ab1dea8> (a java.lang.Runtime)
at java.lang.System.load(System.java:1086)
at com.sun.glass.utils.NativeLibLoader.loadLibraryFullPath(NativeLibLoader.java:201)
at com.sun.glass.utils.NativeLibLoader.loadLibraryInternal(NativeLibLoader.java:94)
at com.sun.glass.utils.NativeLibLoader.loadLibrary(NativeLibLoader.java:39)
- locked <0x000000076b4185c0> (a java.lang.Class for com.sun.glass.utils.NativeLibLoader)
at com.sun.javafx.font.PrismFontFactory.lambda$static$244(PrismFontFactory.java:100)
at com.sun.javafx.font.PrismFontFactory$$Lambda$70/1988937384.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.font.PrismFontFactory.<clinit>(PrismFontFactory.java:98)
at com.sun.javafx.text.PrismTextLayout.<clinit>(PrismTextLayout.java:67)
at com.sun.javafx.text.PrismTextLayoutFactory.<clinit>(PrismTextLayoutFactory.java:33)
at com.sun.javafx.tk.quantum.QuantumToolkit.getTextLayoutFactory(QuantumToolkit.java:1086)
at com.sun.javafx.scene.control.skin.Utils.<clinit>(Utils.java:90)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:348)
at com.sun.javafx.css.StyleManager.getURL(StyleManager.java:863)
at com.sun.javafx.css.StyleManager.loadStylesheetUnPrivileged(StyleManager.java:1075)
- locked <0x000000076c3bc948> (a java.lang.Object)
at com.sun.javafx.css.StyleManager.loadStylesheet(StyleManager.java:935)
at com.sun.javafx.css.StyleManager._setDefaultUserAgentStylesheet(StyleManager.java:1395)
- locked <0x000000076c3bc948> (a java.lang.Object)
at com.sun.javafx.css.StyleManager.setUserAgentStylesheets(StyleManager.java:1227)
- locked <0x000000076c3bc948> (a java.lang.Object)
at com.sun.javafx.application.PlatformImpl.lambda$_setPlatformUserAgentStylesheet$181(PlatformImpl.java:698)
at com.sun.javafx.application.PlatformImpl$$Lambda$65/566730701.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl._setPlatformUserAgentStylesheet(PlatformImpl.java:697)
at com.sun.javafx.application.PlatformImpl.setPlatformUserAgentStylesheet(PlatformImpl.java:548)
at com.sun.javafx.application.PlatformImpl.setDefaultPlatformUserAgentStylesheet(PlatformImpl.java:512)
at javafx.scene.control.Control.<clinit>(Control.java:87)
at com.example.SeparateThreadAsync.start(SeparateThreadAsync.java:37)
at com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$161(LauncherImpl.java:863)
at com.sun.javafx.application.LauncherImpl$$Lambda$56/1315653396.run(Unknown Source)
at com.sun.javafx.application.PlatformImpl.lambda$runAndWait$174(PlatformImpl.java:326)
at com.sun.javafx.application.PlatformImpl$$Lambda$47/1212899836.run(Unknown Source)
at com.sun.javafx.application.PlatformImpl.lambda$null$172(PlatformImpl.java:295)
at com.sun.javafx.application.PlatformImpl$$Lambda$49/1963951195.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.application.PlatformImpl.lambda$runLater$173(PlatformImpl.java:294)
at com.sun.javafx.application.PlatformImpl$$Lambda$48/1289696681.run(Unknown Source)
at com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:95)
a <- 2
b <- 3 # Replace these with your real starting values
for (i in 1:10) {
a <- (a*1.5) - (b*4)
print(c(i, a))
}
语句不是必需的,但有助于显示每个步骤正在发生的事情:您的迭代与这些起始值有所不同。
print