Re: [R] Problem with filling dataframe's column

2023-06-14 Thread avi.e.gross
10:34 PM To: avi.e.gr...@gmail.com Cc: Bert Gunter ; R-help@r-project.org Subject: Re: [R] Problem with filling dataframe's column Consider m <- list(foo=c(1,2),"B'ar"=as.matrix(1:4,2,2),"!*#"=c(FALSE,TRUE)) It is a collection of elements of different types/structures

Re: [R] Problem with filling dataframe's column

2023-06-14 Thread Richard O'Keefe
2023 6:15 PM > To: avi.e.gr...@gmail.com > Cc: javad bayat ; R-help@r-project.org > Subject: Re: [R] Problem with filling dataframe's column > > Below. > > > On Tue, Jun 13, 2023 at 2:18 PM avi.e.gr...@gmail.com> > wrote: > > > > > > Javad, > > > >

Re: [R] Problem with filling dataframe's column

2023-06-13 Thread avi.e.gross
and it looks like … ABOVE From: Bert Gunter Sent: Tuesday, June 13, 2023 6:15 PM To: avi.e.gr...@gmail.com Cc: javad bayat ; R-help@r-project.org Subject: Re: [R] Problem with filling dataframe's column Below. On Tue, Jun 13, 2023 at 2:18 PM mailto:avi.e.gr...@gmail.com> >

Re: [R] Problem with filling dataframe's column

2023-06-13 Thread Bert Gunter
ot; and others like me call programming and that don't necessarily fit well together. > > > -Original Message- > From: R-help r-help-boun...@r-project.org On Behalf Of javad bayat > Sent: Tuesday, June 13, 2023 3:47 PM > To: Eric Berger ericjber...@gmail.com <mailto:er

Re: [R] Problem with filling dataframe's column

2023-06-13 Thread avi.e.gross
June 13, 2023 3:47 PM To: Eric Berger ericjber...@gmail.com <mailto:ericjber...@gmail.com> Cc: R-help@r-project.org <mailto:R-help@r-project.org> Subject: Re: [R] Problem with filling dataframe's column Dear all; I used these codes and I get what I wanted. Sincerely pat = c("Level

Re: [R] Problem with filling dataframe's column

2023-06-13 Thread Bill Dunlap
It is safer to use !grepl(...) instead of -grep(...) here. If there are no matches, the latter will give you a zero-row data.frame while the former gives you the entire data.frame. E.g., > d <- data.frame(a=c("one","two","three"), b=c(10,20,30)) > d[-grep("Q", d$a),] [1] a b <0 rows> (or

Re: [R] Problem with filling dataframe's column

2023-06-13 Thread Rui Barradas
Às 17:18 de 13/06/2023, javad bayat escreveu: Dear Rui; Hi. I used your codes, but it seems it didn't work for me. pat <- c("_esmdes|_Des Section|0") dim(data2) [1] 281549 9 grep(pat, data2$Layer) dim(data2) [1] 281549 9 What does grep function do? I expected the

Re: [R] Problem with filling dataframe's column

2023-06-13 Thread javad bayat
Dear all; I used these codes and I get what I wanted. Sincerely pat = c("Level 12","Level 22","0") data3 = data2[-which(data2$Layer == pat),] dim(data2) [1] 281549 9 dim(data3) [1] 244075 9 On Tue, Jun 13, 2023 at 11:36 AM Eric Berger wrote: > Hi Javed, > grep returns the positions

Re: [R] Problem with filling dataframe's column

2023-06-13 Thread Eric Berger
Hi Javed, grep returns the positions of the matches. See an example below. > v <- c("abc", "bcd", "def") > v [1] "abc" "bcd" "def" > grep("cd",v) [1] 2 > w <- v[-grep("cd",v)] > w [1] "abc" "def" > On Tue, Jun 13, 2023 at 8:50 AM javad bayat wrote: > > Dear Rui; > Hi. I used your codes, but it

Re: [R] Problem with filling dataframe's column

2023-06-12 Thread javad bayat
Dear Rui; Hi. I used your codes, but it seems it didn't work for me. > pat <- c("_esmdes|_Des Section|0") > dim(data2) [1] 281549 9 > grep(pat, data2$Layer) > dim(data2) [1] 281549 9 What does grep function do? I expected the function to remove 3 rows of the dataframe. I do

Re: [R] Problem with filling dataframe's column

2023-06-12 Thread Rui Barradas
Às 23:13 de 12/06/2023, javad bayat escreveu: Dear Rui; Many thanks for the email. I tried your codes and found that the length of the "Values" and "Names" vectors must be equal, otherwise the results will not be useful. For some of the characters in the Layer column that I do not need to be

Re: [R] Problem with filling dataframe's column

2023-06-11 Thread avi.e.gross
mutate() or other methods. -Original Message- From: R-help On Behalf Of javad bayat Sent: Sunday, June 11, 2023 4:05 PM To: R-help@r-project.org Subject: [R] Problem with filling dataframe's column Dear R users; I am trying to fill a column based on a specific value in another column of

Re: [R] Problem with filling dataframe's column

2023-06-11 Thread Rui Barradas
Às 13:18 de 11/06/2023, Rui Barradas escreveu: Às 22:54 de 11/06/2023, javad bayat escreveu: Dear Rui; Many thanks for your email. I used one of your codes, "data2$LU[which(data2$Layer == "Level 12")] <- "Park"", and it works correctly for me. Actually I need to expand the codes so as to

Re: [R] Problem with filling dataframe's column

2023-06-11 Thread Rui Barradas
Às 22:54 de 11/06/2023, javad bayat escreveu: Dear Rui; Many thanks for your email. I used one of your codes, "data2$LU[which(data2$Layer == "Level 12")] <- "Park"", and it works correctly for me. Actually I need to expand the codes so as to consider all "Levels" in the "Layer" column. There are

Re: [R] Problem with filling dataframe's column

2023-06-11 Thread javad bayat
Dear Rui; Many thanks for your email. I used one of your codes, "data2$LU[which(data2$Layer == "Level 12")] <- "Park"", and it works correctly for me. Actually I need to expand the codes so as to consider all "Levels" in the "Layer" column. There are more than hundred levels in the Layer column.

Re: [R] Problem with filling dataframe's column

2023-06-11 Thread Rui Barradas
Às 21:05 de 11/06/2023, javad bayat escreveu: Dear R users; I am trying to fill a column based on a specific value in another column of a dataframe, but it seems there is a problem with the codes! The "Layer" and the "LU" are two different columns of the dataframe. How can I fix this? Sincerely

[R] Problem with filling dataframe's column

2023-06-11 Thread javad bayat
Dear R users; I am trying to fill a column based on a specific value in another column of a dataframe, but it seems there is a problem with the codes! The "Layer" and the "LU" are two different columns of the dataframe. How can I fix this? Sincerely for (i in 1:nrow(data2$Layer)){ if