由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Statistics版 - how to save dataset generated by a function in R
相关主题
在R里怎么跳到指定的地方?Predict values of vectors generated by black box functions
sas base 123 question 82 answer is wrong?R package: how to use xx.rd files to generate PDF document?
求救:SAS programmer面试题!R: generate random number的问题
How to generate PDF report in SAS?sas question
how to generate a large SAS data set?Help for beginner of Macro
a simple question. Thank you in advance请教一个问题包子答谢:An I/O error has occurred on file abc.DATA
Generate and Retrieve Many Objects with Sequential Names请教 C++ 里面 optmization 函数及其用法
请教一个R作图的命令Help: an I/O ERROR occured
相关话题的讨论汇总
话题: sim话题: function话题: dataset话题: generated话题: save
进入Statistics版参与讨论
1 (共1页)
a********a
发帖数: 346
1
x=function(n){
sim=rnorm(n)
return(sim)
}
x(n=10)
> x(n=10)
[1] 0.3466314 0.7477493 1.1274950 0.3848275 0.9549582 1.1843009
[7] 0.3804086 -1.4802425 1.4219162 1.5410326
> sim
Error: object 'sim' not found
I generate dataset 'sim' from a R function. As you can see from the result,
I can see the data I generated, but why the sim could not be found? As I
can not get sim, so I can not save the data as a text file. Do you know how
to save a dataset generated within a function?
Thanks
l*********s
发帖数: 5409
2
sim is a local object, which is deleted upon finishing of your function call
a********a
发帖数: 346
3
I think you are right. Do you know how can I get the dataset?
Thanks
b**********i
发帖数: 1059
4
This is the most basic question I've ever seen. You use sim<-x(10)

【在 a********a 的大作中提到】
: I think you are right. Do you know how can I get the dataset?
: Thanks

D******n
发帖数: 2836
5
This is one of the dumb things about R, it doesn't have pass by reference
mechanism.....
a********a
发帖数: 346
6
Thank you guys. I figured out it will also work if I write table inside the
function.
x=function(n){
sim=rnorm(n)
return(sim)
write(sim,"path")
}
x(n=10)
1 (共1页)
进入Statistics版参与讨论
相关主题
Help: an I/O ERROR occuredhow to generate a large SAS data set?
SAS format file--- when I load the file 急~~~谢谢~~~a simple question. Thank you in advance
SAS CEDA questionGenerate and Retrieve Many Objects with Sequential Names
请教 sas functions请教一个R作图的命令
在R里怎么跳到指定的地方?Predict values of vectors generated by black box functions
sas base 123 question 82 answer is wrong?R package: how to use xx.rd files to generate PDF document?
求救:SAS programmer面试题!R: generate random number的问题
How to generate PDF report in SAS?sas question
相关话题的讨论汇总
话题: sim话题: function话题: dataset话题: generated话题: save