Re: [R] Apply gsub to dataframe to modify row values

2021-08-09 Thread Luigi Marongiu
Thank you, it works! On Mon, Aug 9, 2021 at 3:26 PM Andrew Simmons wrote: > > Hello, > > > There are two convenient ways to access a column in a data.frame using `$` > and `[[`. Using `df` from your first email, we would do something like > > df <- data.frame(VAR = 1:3, VAL = c("value is blue",

Re: [R] Apply gsub to dataframe to modify row values

2021-08-09 Thread Andrew Simmons
Hello, There are two convenient ways to access a column in a data.frame using `$` and `[[`. Using `df` from your first email, we would do something like df <- data.frame(VAR = 1:3, VAL = c("value is blue", "Value is red", "empty")) df$VAL df[["VAL"]] The two convenient ways to update / / replac

Re: [R] Apply gsub to dataframe to modify row values

2021-08-09 Thread Luigi Marongiu
I wanted to remove possible white spaces before or after the string. Actually, it worked, I used `gsub("[:blank:]*val[:blank:]*", "", df$VAL, ignore.case=TRUE)`. I don't know why in the example there were extra columns -- they did not came out in the real case. Thank you, I think the case is closed

Re: [R] Apply gsub to dataframe to modify row values

2021-08-09 Thread Jim Lemon
Hi Luigi, You want to get rid of certain strings in the "VAL" column. You are assigning to: df[df$VAL] Error in `[.data.frame`(df, df$VAL) : undefined columns selected when I think you should be assigning to: df$VAL What do you want to remove other than "[V|v]alue is" ? JIim On Mon, Aug 9, 20

Re: [R] Apply gsub to dataframe to modify row values

2021-08-09 Thread Luigi Marongiu
Sorry, silly question, gsub works already with regex. But still, if I add `[[:blank:]]` still I don't get rid of all instances. And I am keeping obtaining extra columns ``` > df[df$VAL] = gsub("[[:blank:]Value is]", "", df$VAL, ignore.case=TRUE) > df[df$VAL] = gsub("[[:blank:]Value is]", "", df$VAL

Re: [R] Apply gsub to dataframe to modify row values

2021-08-09 Thread Luigi Marongiu
Thank you, that is much appreciated. But on the real data, the substitution works only on few instances. Is there a way to introduce regex into this? Cheers Luigi On Mon, Aug 9, 2021 at 11:01 AM Jim Lemon wrote: > > Hi Luigi, > Ah, now I see: > > df$VAL<-gsub("Value is","",df$VAL,ignore.case=TRU

Re: [R] Apply gsub to dataframe to modify row values

2021-08-09 Thread Jim Lemon
Hi Luigi, Ah, now I see: df$VAL<-gsub("Value is","",df$VAL,ignore.case=TRUE) df VAR VAL 1 1 blue 2 2 red 3 3 empty Jim On Mon, Aug 9, 2021 at 6:43 PM Luigi Marongiu wrote: > > Hello, > I have a dataframe where I would like to change the string of certain > rows, essentially I am lo

[R] Apply gsub to dataframe to modify row values

2021-08-09 Thread Luigi Marongiu
Hello, I have a dataframe where I would like to change the string of certain rows, essentially I am looking to remove some useless text from the variables. I tried with: ``` > df = data.frame(VAR = 1:3, VAL = c("value is blue", "Value is red", "empty")) > df[df$VAL] = gsub("value is ", "", df$VAL,