Subtracting test string from vectors

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

Subtracting test string from vectors

Cren
Hi all,

let I have two text string:

one <- c("ciao","zio","caio","bello")
two <- c("caio","zio")


I would like to obtain a new text string which is one - two like this one:

[1] "ciao" "bello"

because "caio" and "zio" elements have been subtracted from one.

What's the most efficient way to obtain this?

Thank you,
Reply | Threaded
Open this post in threaded view
|

Re: Subtracting test string from vectors

Rui Barradas
Hello,

?setdiff
setdiff(one, two)

Hope this helps,

Rui Barradas
Cren wrote
Hi all,

let I have two text string:

one <- c("ciao","zio","caio","bello")
two <- c("caio","zio")


I would like to obtain a new text string which is one - two like this one:

[1] "ciao" "bello"

because "caio" and "zio" elements have been subtracted from one.

What's the most efficient way to obtain this?

Thank you,
Reply | Threaded
Open this post in threaded view
|

Re: Subtracting test string from vectors

Cren
Rui Barradas wrote
Hello,

?setdiff
setdiff(one, two)
Thank you for your help, Rui.

But

> setdiff(one,two)
[1] "ciao"


Where's "bello"?
Reply | Threaded
Open this post in threaded view
|

Re: Subtracting test string from vectors

Rui Barradas
Hello,

It works with me.

> one <- c("ciao","zio","caio","bello")
> two <- c("caio","zio")
> setdiff(one, two)
[1] "ciao"  "bello"

Are you sure of the values in your 'one' and 'two'?

Rui Barradas
Cren wrote
Rui Barradas wrote
Hello,

?setdiff
setdiff(one, two)
Thank you for your help, Rui.

But

> setdiff(one,two)
[1] "ciao"


Where's "bello"?
Reply | Threaded
Open this post in threaded view
|

Re: Subtracting test string from vectors

arun kirshna
In reply to this post by Cren
Hi,

> one <- c("ciao","zio","caio","bello")
> two<-c("ciao","zio")

setdiff(one,two)
[1] "caio"  "bello"


A.K.

----- Original Message -----
From: Cren <[hidden email]>
To: [hidden email]
Cc:
Sent: Friday, June 1, 2012 6:13 AM
Subject: Re: [R] Subtracting test string from vectors


Rui Barradas wrote
>
> Hello,
>
> ?setdiff
> setdiff(one, two)
>
Thank you for your help, Rui.

But

*> setdiff(one,two)
[1] "ciao"*

Where's "bello"?

--
View this message in context: http://r.789695.n4.nabble.com/Subtracting-test-string-from-vectors-tp4632049p4632053.html
Sent from the R help mailing list archive at Nabble.com.

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.