You need to add "-": ` (dat3 <- dat1[-unique(c(BadName, BadAge,
BadWeight)), ])` which makes the command NOT).
David
On Sun, Jan 30, 2022 at 11:00 AM Val wrote:
> Thank you David. What about if I want to list the excluded rows? I used
> this (dat3 <- dat1[unique(c(BadName, BadAge, BadWeight
Thank you David.
What about if I want to list the excluded rows?
I used this
(dat3 <- dat1[unique(c(BadName, BadAge, BadWeight)), ])
It did not work.The desired output is,
Alex, 20, 13X
John, 3BC, 175
Jack3, 34, 140
Thank you,
On Sat, Jan 29, 2022 at 10:15 PM David Carlson wrote:
It is possible that there would be errors on the same row for different
columns. This does not happen in your example. If row 4 was "John6, 3BC,
175X" then row 4 would be included 3 times, but we only need to remove it
once. Removing the duplicates is not necessary since R would not get
confused, b
;grep("[a-zA-Z]", dat1$Weight, invert = TRUE))
> > result <- dat1[rows.keep,]
> >
> >
>
> Using the same idea, another two options, both with Reduce.
>
> The 1st uses Avi's grep and regex's, the latter could be the character
> classes "
Rui:
You made my day! -- or at least considerably improved it. Your
solution was clever and clear. IMHO, it is also a terrific example of
why one should expend the effort to really learn the core features of
the language before plunging into packages with alternative paradigms.
(But lots of wise f
, invert = TRUE))
result <- dat1[rows.keep,]
-Original Message-
From: Avi Gross via R-help
To: ruipbarra...@sapo.pt ; dcarl...@tamu.edu
; bgunter.4...@gmail.com
Cc: r-help@r-project.org
Sent: Sat, Jan 29, 2022 1:04 pm
Subject: Re: [R] Row exclude
There are many creative ways to
lt;- Map(\(x, r) grep(r, x, invert = TRUE), dat1, regex)
keep2 <- Reduce(intersect, keep2)
identical(keep1, keep2)
#[1] TRUE
Hope this helps,
Rui Barradas
-Original Message-
From: Rui Barradas
To: David Carlson ; Bert Gunter
Cc: r-help@R-project.org (r-help@r-project.org)
-Original Message-
From: Rui Barradas
To: David Carlson ; Bert Gunter
Cc: r-help@R-project.org (r-help@r-project.org)
Sent: Sat, Jan 29, 2022 3:46 am
Subject: Re: [R] Row exclude
Hello,
Getting creative, here is another way with mapply.
regex <- list("[[:digit:]]",
As character 'polluted' entries will cause a column to be read in (via
read.table and relatives) as factor or character data, this sounds like a
job for regular expressions. If you are not familiar with this subject,
time to learn. And, yes, some heavy lifting will be required.
See ?regexp for a st
9 matches
Mail list logo