[R] save a data frame in environment

Uwe Ligges ligges at statistik.tu-dortmund.de
Tue Apr 27 11:44:02 CEST 2010


Don't print them but return() them from your function position() within 
a list. Then you will have a list of two data.frames for later usage 
assigned to your list.


Uwe Ligges


On 27.04.2010 11:37, arnaud Gaboury wrote:
> Dear group,
>
>
>
> Here is my function :
>
>
>
>
>
>
>
> position<-function(x)
>
> {
>
>
>
>
> pose<-read.csv2((paste(c("LSCPos",x,".csv"),collapse="")),dec=".",sep=",",as
> .is=T,h=T,skip=1)[,c(4,8,14,15)]
>
>    pose$CREATED.DATE<-as.Date(pose$CREATED.DATE,"%d/%m/%y")
>
>    futures<-pose[-grep("USD",pose[,1]),]
>
>
>    colnames(futures)<-c("CONTRAT","CREATED.DATE","QUANTITY","SETTLEMENT")
>
>    lme<-pose[grep("USD",pose[,1]),]
>
>    lme$DESCRIPTION<- gsub(" *(\\d+/\\d+/\\d+) *$", "", lme$DESCRIPTION)
>
>    library(plyr)
>
>    PositionFut<-ddply(futures, c("CONTRAT","SETTLEMENT"), summarise,
> POSITION=sum(QUANTITY))[,c(1,3,2)]
>
>    PositionLme<-unique(ddply(lme, c("DESCRIPTION"), summarise,
> POSITION=sum(QUANITY),DATE=max(CREATED.DATE),SETTLEMENT=CLOSING.PRICE[CREATE
> D.DATE == max(CREATED.DATE)]))[,-3]
>
>
>
>
>
>    print(PositionFut)
>
>    print(PositionLme)
>
>
>
> }
>
>
>
> As I'm totally new to this kind of sport, i.e. writing code, the code is
> maybe ugly, but it does work. Now, one thing is missing.
>
>   I want to have the 2 Dataframes "PositionFut"&  "PositionLme" in my
> environment, as I will need them later for another function. If I do a
> save(), it will be saved in my directory, but won't see it when I do ls(),
> even if I do a get() before. What is the process to save these 2 objects in
> order to access them later in another function?
>
>
>
>
>
> ***************************
>
> Arnaud Gaboury
>
> Mobile: +41 79 392 79 56
>
> BBM: 255B488F
>
> ***************************
>
>
>
>
> 	[[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list