Re: [R] Select dataframe row containing a digit

2022-12-01 Thread Luigi Marongiu
Thank you, those are all viable solutions. Regards Luigi On Wed, Nov 30, 2022 at 8:59 PM Rolf Turner wrote: > > > 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

Re: [R] Select dataframe row containing a digit

2022-11-30 Thread Rolf Turner
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

Re: [R] Select dataframe row containing a digit

2022-11-30 Thread Bert Gunter
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 =

Re: [R] Select dataframe row containing a digit

2022-11-30 Thread Bert Gunter
... 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"

Re: [R] Select dataframe row containing a digit

2022-11-30 Thread Rui Barradas
À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

Re: [R] Select dataframe row containing a digit

2022-11-30 Thread Michael Dewey
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

Re: [R] Select dataframe row containing a digit

2022-11-30 Thread Luigi Marongiu
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", > >

Re: [R] Select dataframe row containing a digit

2022-11-30 Thread Ivan Krylov
В 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

[R] Select dataframe row containing a digit

2022-11-30 Thread Luigi Marongiu
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