我处理具有多个且变化的时间戳记的大型数据集。结果,我找到了通过使用这些图绘制和标识所需数据范围来识别数据子集的最简单方法。
我想运行一个绘制数据子集的函数,然后允许我通过查看该图输入变量(尚未弄清楚如何自动执行此步骤)并继续运行该函数。但是,在函数中进行绘图时,将在生成绘图之前运行下一行-因此我看不到它。谁能指出我正确的方向?这是我想做的事的一个例子:
data.initialization <- function(){
p = c(1,2,3,4,5)
l = c(5,6,7,6,5) #initialize some data
qplot(p,l) #plot the data so I can see what it looks like
x = (readline("Input a value based on the plot: ")) #use the information from looking at the plot to input a value
y = f(x) #do some more operations with the input variable
}
答案 0 :(得分:0)
您需要在qplot调用周围添加print()以获得输出
library(ggplot2)
f <- function(z) {
as.numeric(z)+2
}
data.initialization <- function(){
p = c(1,2,3,4,5)
l = c(5,6,7,6,5) #initialize some data
print(qplot(p,l)) #plot the data so I can see what it looks like
x = (readline("Input a value based on the plot: ")) #use the information from looking at the plot to input a value
y = f(x) #do some more operations with the input variable
y
}
data.initialization()