[R] Remove cases with -Inf from a data frame
Martin Møller Skarbiniks Pedersen
tr@xp|@yer @end|ng |rom gm@||@com
Sat Feb 16 17:14:33 CET 2019
On Sat, 16 Feb 2019 at 16:07, AbouEl-Makarim Aboueissa <
abouelmakarim1962 using gmail.com> wrote:
>
> I have a log-transformed data frame with some *-Inf* data values.
>
> *my question: *how to remove all rows with *-Inf* data value from that
data
> frame?
Hi,
Here is a solution which uses apply.
First a data-frame as input:
set.seed(1)
df <- data.frame(w = sample(c(-Inf,1:20), 10),
x = sample(c(-Inf,1:20), 10),
y = sample(c(-Inf,1:20), 10),
z = sample(c(-Inf,1:20), 10))
df <- df[-(unlist(apply(df, 2, function(x) which(x == -Inf)))),]
Regards
Martin
[[alternative HTML version deleted]]
More information about the R-help
mailing list