On Wed, 30 Nov 2022 13:40:50 +0100
Luigi Marongiu wrote:
> Hello,
> I have a data frame where some lines containing strings including
> digits. How do I select those rows and change their values?
>
> In essence, I have a data frame with different values assigned to the
> column "val". I am for
I just noticed that I forgot about the "" <-> NA clause. So my "onego"
solution should be:
df <- ## to assign back to df or perhaps a new frame
within(df, val <-
ifelse(val == "", NA,
ifelse(grepl("P|Y", val, ignore.case = TRUE), "POS",
ifelse(grepl("N", val, ignore.case = TR
... or, if you wanted to do it all in one go:
within(df, val <-
ifelse(grepl("P|Y", val, ignore.case = TRUE), "POS",
ifelse(grepl("N", val, ignore.case = TRUE), "NEG","NUM")))
## which gives
[1] "NUM" "POS" "POS" "POS" "POS" "NUM" "NEG" "NEG" "NUM" "NUM"
for the "val" column
Às 12:40 de 30/11/2022, Luigi Marongiu escreveu:
Hello,
I have a data frame where some lines containing strings including digits.
How do I select those rows and change their values?
In essence, I have a data frame with different values assigned to the
column "val". I am formatting everything to
I suspect [[:digit:]] might have done what you want.
Michael
On 30/11/2022 13:04, Luigi Marongiu wrote:
Thank you,
I have been trying with [:digit:] but did not work. It worked with
`df$val[grepl('[0-9]', df$val)] = "NUM"`
On Wed, Nov 30, 2022 at 2:02 PM Ivan Krylov wrote:
В Wed, 30 Nov 202
Thank you,
I have been trying with [:digit:] but did not work. It worked with
`df$val[grepl('[0-9]', df$val)] = "NUM"`
On Wed, Nov 30, 2022 at 2:02 PM Ivan Krylov wrote:
>
> В Wed, 30 Nov 2022 13:40:50 +0100
> Luigi Marongiu пишет:
>
> > I am formatting everything to either "POS" and "NEG",
> >
В Wed, 30 Nov 2022 13:40:50 +0100
Luigi Marongiu пишет:
> I am formatting everything to either "POS" and "NEG",
> but values entered as number should get the value "NUM".
> How do I change such values?
Thanks for providing an example!
One idea would be to use a regular expression to locate numb
Hello,
I have a data frame where some lines containing strings including digits.
How do I select those rows and change their values?
In essence, I have a data frame with different values assigned to the
column "val". I am formatting everything to either "POS" and "NEG",
but values entered as numbe
8 matches
Mail list logo