Hi Luigi, Maybe this: testdf<-data.frame(A=1,B=2,C=3) > testdf A B C 1 1 2 3 toNull<-function(x) return(NULL) testdf<-sapply(testdf,toNull)
Jim On Thu, Sep 27, 2018 at 5:29 PM Luigi Marongiu <marongiu.lu...@gmail.com> wrote: > > Dear all, > I would like to erase the content of a dataframe -- but not the > dataframe itself -- in a simple and fast way. > At the moment I do that by re-defining the dataframe itself in this way: > > > df <- data.frame(A = numeric(), > + B = numeric(), > + C = character()) > > # assign > > A <- 5 > > B <- 0.6 > > C <- 103 > > # load > > R <- cbind(A, B, C) > > df <- rbind(df, R) > > df > A B C > 1 5 0.6 103 > > # erase > > df <- data.frame(A = numeric(), > + B = numeric(), > + C = character()) > > df > [1] A B C > <0 rows> (or 0-length row.names) > > > > Is there a way to erase the content of the dataframe in a simplier > (acting on all the dataframe at once instead of naming each column > individually) and nicer (with a specific erasure command instead of > re-defyining the object itself) way? > > Thank you. > -- > Best regards, > Luigi > > ______________________________________________ > R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see > 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. ______________________________________________ R-help@r-project.org mailing list -- To UNSUBSCRIBE and more, see 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.