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 for

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 = TR

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" column

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 202

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 numb

[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 numbe