Ram H. Sharma
2011-Sep-04 21:20 UTC
[R] output and save multiple dataset from a function: sorry I could not figure out this....
Dear list:
Before going into my problem, R list has been awesome for me ...thank you
for the help. I have a simple problem, however I could get a answer to it...
#my data
myseed <- c(1001:1030)
gend <- function(x){
set.seed(x)
var <- rep(1:4, c(rep(4, 4)))
vary <- rnorm(length(var), 50, 10)
mat <- matrix(sample(c(-1,0,1), c(10*length(var)), replace = TRUE), ncol 10)
mydat <- data.frame(var, vary, mat)
#filename = paste("file", x, ".txt", sep="")
#save(mydat, list = filename, file = "my.Rdata")
}
lapply (myseed, gend)
This works and I can create 30 random data set in the list. So far so good.
My individual data are huge ( 1 million datapoints each) and I need to
generate > 2000 data set. So it may not be good strategy to write as *.csv
file and read with take a lot of computing time.
My attempt is to output and save individual Rdata sets and load it using
load ("my.Rdata") function. It is more fast this way. But could not
figure
out how to do it !!!!!!!!!!!!!!!
In above function I have put # some of my attempt to solve this problem....
Any suggestions ....thank you...
-
Ram H
[[alternative HTML version deleted]]
jim holtman
2011-Sep-05 04:29 UTC
[R] output and save multiple dataset from a function: sorry I could not figure out this....
try this:
#my data
myseed <- c(1001:1030)
gend <- function(x){
set.seed(x)
var <- rep(1:4, c(rep(4, 4)))
vary <- rnorm(length(var), 50, 10)
mat <- matrix(sample(c(-1,0,1), c(10*length(var)), replace TRUE), ncol =
10)
mydat <- data.frame(var, vary, mat)
filename = paste("file", x, ".RData", sep="")
save(mydat, file = filename)
}
lapply (myseed, gend)
On Sun, Sep 4, 2011 at 5:20 PM, Ram H. Sharma <sharma.ram.h at gmail.com>
wrote:> Dear list:
> Before going into my problem, R list has been?awesome?for me ...thank you
> for the help. I have a simple problem, however I could get a answer to
it...
> #my data
> myseed <- c(1001:1030)
> gend <- function(x){
> set.seed(x)
> var <- rep(1:4, c(rep(4, 4)))
> vary <- rnorm(length(var), 50, 10)
> mat <- matrix(sample(c(-1,0,1), c(10*length(var)), replace = TRUE), ncol
> 10)
> mydat <- data.frame(var, vary, mat)
> #filename = paste("file", x, ".txt", sep="")
> #save(mydat, list = filename, file = "my.Rdata")
> }
> lapply (myseed, ?gend)
> This works and I can create 30 random data set in the list. So far so good.
> My individual data are huge ( 1 million datapoints each) ?and I need to
> generate > 2000?data set. So it may not be good strategy to write as
*.csv
> file and read with take a lot of computing time.
> My attempt is to output and save individual Rdata sets and load it using
> load ("my.Rdata") function. It is more fast this way. But could
not figure
> out how to do it !!!!!!!!!!!!!!!
> In above function I have put # some of my attempt to solve this problem....
> Any suggestions ....thank you...
>
> -
>
> Ram H
>
--
Jim Holtman
Data Munger Guru
What is the problem that you are trying to solve?