Laura Rodriguez Murillo
2009-Feb-25 16:17 UTC
[R] : record which entry in one file doesn't appear in a different file
Hi dear list, If anybody could help me, it would be great! I have two files: File 1 is a list (one column and around 100000 rows) File 2 is a list with all the names from file one and a few more (one column and more than 100000 rows) What I want is to add a column in file 2 that says which name appeared in file 1 and which doesn't (yes and no would work as a code) It's very important to keep the order of the names in file 2. Thank you! Laura
Tal Galili
2009-Feb-25 16:26 UTC
[R] : record which entry in one file doesn't appear in a different file
Hi Laura. Let's assume file 1 and 2 are vectors loaded in R named: vec1 and vec2, here is a short code (with dummy numbers) for a solution: vec1 <- c(1,2,34,4,3,6,76) vec2 <- c(1,2,34,76,24,62,1,4234,435,4333,4422,304,776) which.vec2.where.in.vec1 <- vec2 %in% vec1 which.vec2.where.in.vec1.turned.into.yes.and.no<-ifelse(which.vec2.where.in.vec1 , "yes", "no") cbind(vec2, which.vec2.where.in.vec1.turned.into.yes.and.no) Cheers, Tal On Wed, Feb 25, 2009 at 6:17 PM, Laura Rodriguez Murillo < laura.lmurillo@gmail.com> wrote:> Hi dear list, > > If anybody could help me, it would be great! > > I have two files: > File 1 is a list (one column and around 100000 rows) > File 2 is a list with all the names from file one and a few more (one > column and more than 100000 rows) > > What I want is to add a column in file 2 that says which name appeared > in file 1 and which doesn't (yes and no would work as a code) > It's very important to keep the order of the names in file 2. > > Thank you! > > Laura > > ______________________________________________ > R-help@r-project.org 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. >-- ---------------------------------------------- My contact information: Tal Galili Phone number: 972-50-3373767 FaceBook: Tal Galili My Blogs: www.talgalili.com www.biostatistics.co.il [[alternative HTML version deleted]]
Patrizio Frederic
2009-Feb-25 16:41 UTC
[R] : record which entry in one file doesn't appear in a different file
hey Laura,
I hope this help
f1 = c("a","b","c")
f2 = c("b","a","c","d")
match(f2,f1)
f3 = match(f2,f1,0)
?match
cbind(f2,f3)
cbind(f2,f3>0)
f4 = ifelse(f3>0,"yes","no")
cbind(f2,f4)
data.frame(f2,f4)
Patrizio
2009/2/25 Laura Rodriguez Murillo <laura.lmurillo at
gmail.com>:> Hi dear list,
>
> If anybody could help me, it would be great!
>
> I have two files:
> File 1 is a list (one column and around 100000 rows)
> File 2 is a list with all the names from file one and a few more (one
> column and more than 100000 rows)
>
> What I want is to add a column in file 2 that says which name appeared
> in file 1 and which doesn't (yes and no would work as a code)
> It's very important to keep the order of the names in file 2.
>
> Thank you!
>
> Laura
>
> ______________________________________________
> R-help at r-project.org 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.
>