[R] Function for Data Frame

arun smartpink111 at yahoo.com
Mon Apr 29 18:16:28 CEST 2013


Hi,
If it is for the list:
lst1<- list(x,x,x)
 lst1<-lapply(lst1,myfunc)



----- Original Message -----
From: arun <smartpink111 at yahoo.com>
To: "Sparks, John James" <jspark4 at uic.edu>
Cc: R help <r-help at r-project.org>
Sent: Monday, April 29, 2013 12:13 PM
Subject: Re: [R] Function for Data Frame



Hi,
If I understand it correctly, 
x<-myfunc(x)
x
#  V2 V3
#1  2  3
#2  2  3
#3  2  2
#4  2  2
#5  1  1
A.K.

----- Original Message -----
From: "Sparks, John James" <jspark4 at uic.edu>
To: r-help at r-project.org
Cc: 
Sent: Monday, April 29, 2013 10:23 AM
Subject: [R] Function for Data Frame

Dear R Helpers,

I have about 20 data frames that I need to do a series of data scrubbing
steps to.  I have the list of data frames in a list so that I can use
lapply.  I am trying to build a function that will do the data scrubbing
that I need.  However, I am new to functions and there is something
fundamental that I am not understanding.  I use the return function at the
end of the function and this completes the data processing specified in
the function, but leaves the data frame that I want changed unaffected. 
How do I get my function to apply its results to the data frame in
question instead of simply displaying the results to the screen?

Any helpful guidance would be most appreciated.

--John Sparks


x=as.data.frame(matrix(c(1,2,3,
        1,2,3,
        1,2,2,
        1,2,2,
       1,1,1),ncol=3,byrow=T))


myfunc<-function(DF){
DF<-subset(DF,select=-c(V1))
return(DF)
}

myfunc(x)

#How to get this change to data frame x?
#And preferrably not send the results to the screen?
x

______________________________________________
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