[R] Erase content of dataframe in a single stroke
Luigi Marongiu
m@rongiu@luigi @ending from gm@il@com
Thu Sep 27 09:28:49 CEST 2018
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
More information about the R-help
mailing list