Displaying 3 results from an estimated 3 matches for "zero2na".
Did you mean:
verona
2024 Sep 16
1
findInterval
...value in `x` equal to the corresponding component
of `seek` and we wish to return an output the same length as `seek` using
`findInterval` to perform the search. This returns the correct result:
dat <- data.frame(x = c(2, 2, 3, 4, 4, 4),
y = c(37, 12, 19, 30, 6, 15),
seek = 1:6)
zero2na <- function(x) replace(x, x == 0, NA)
dat |>
transform(dat, result = y[ zero2na(findInterval(seek, x)) ] ) |>
_$result
## [1] NA 12 19 15 15 15
Since `findInterval` returns an index it is natural that the next step be
to use the index and it is also common that we want a resu...
2024 Sep 17
1
findInterval
...k` and we wish to return an output the same length as `seek` using
> `findInterval` to perform the search. This returns the correct result:
> dat <- data.frame(x = c(2, 2, 3, 4, 4, 4),
> y = c(37, 12, 19, 30, 6, 15),
> seek = 1:6)
> zero2na <- function(x) replace(x, x == 0, NA)
> dat |>
> transform(dat, result = y[ zero2na(findInterval(seek, x)) ] ) |>
> _$result
> ## [1] NA 12 19 15 15 15
I'd write that as
with(dat, y[ zero2na(findInterval(seek, x)) ] )
so I can read it with jumping ho...
2004 Nov 16
3
Changing zeros to NAs in a data frame
Dear R People:
I have a data frame with some columns that are numeric and some which are
factors.
There are zeros in the numeric columns and I would like to change them to
NAs. However, there are zeros in some of the factor columns, and I would
like them to be left alone.
Is there a "global" way to do this, please? I was thinking about use the
results from "str" but am