Skip to content
Prev 316621 / 398506 Next

use name (not values!) of a dataframe inside a funktion

Hi

Maybe others can help you but here is my comment. I already use R for many years and never used such construction. Objects in global environment shall not be modified by functions it is a bad practice. Imagine you have some data frame you prepared and controlled in many steps and use some function from a package. 

If this function scrambles object without warning and the result cannot be easily repaired I would be tempted to curse the function with many nasty four letter words.

When I want to change some data by a function I use

fff <- function(x, no=2) {
x[,no]<-factor(x[, no])
x
}
 
dfb.f <- fff(dfb)

In this case I will end with old object dfb and new object dfb.f. Of course it is possible to use

dfb <- fff(dfb)

and in this case dfb object is changed

Petr
Message-ID: <6E8D8DFDE5FA5D4ABCB8508389D1BF88027B4541@SRVEXCHMBX.precheza.cz>
In-Reply-To: <CACwq_u+TF3hjpVrDDmtHyYmpXX87Uoo3pu91icVPkf3sDisuLA@mail.gmail.com>