match a task No. to a few person-IDs

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Mat
Reply | Threaded
Open this post in threaded view
|

match a task No. to a few person-IDs

Mat
This post was updated on .
hello together,

i have a task No. in a data.frame
       Task_No       Team    
1    49397           1      
2    49396           1  

and now i want to match my Person-IDs to each Task_No. My Person Ids look like this one:
    ID        Team
1 5019     1
2 472     1
3 140     1
4 5013     1

The solution should be this:

       Task_No       Team     ID
1    49397          1           5019
2    49397          1           472
3    49397          1           140
4    49397          1           5013
5    49396          1         5019
6    49396          1            472
7    49396          1            140
8    49396          1            5013

perhabs anyone can help me.

Thank you

Mat
Reply | Threaded
Open this post in threaded view
|

Re: match a task No. to a few person-IDs

arun kirshna
Hi,
Try this:
dat1<- read.table(text="
      Task_No      Team  
A    49397        1        
B    49396        1
",sep="",header=TRUE)

dat2<- read.table(text="
    ID        Team
A 5019    1
B 472    1
C 140    1
D 5013    1
",sep="",header=TRUE)
 res1<- as.matrix(merge(dat1,dat2,by="Team"))
 row.names(res1)<-LETTERS[match(res1[,2],dat1[,1])] 


library(plyr)
res2<- as.matrix(join(dat1,dat2,by="Team"))
 row.names(res2)<-LETTERS[match(res2[,1],dat1[,1])]
 res2
#  Task_No Team   ID
#A   49397    1 5019
#A   49397    1  472
#A   49397    1  140
#A   49397    1 5013
#B   49396    1 5019
#B   49396    1  472
#B   49396    1  140
#B   49396    1 5013
A.K.




----- Original Message -----
From: Mat <[hidden email]>
To: [hidden email]
Cc:
Sent: Friday, February 15, 2013 4:45 AM
Subject: [R] match a task No. to a few person-IDs

hello together,

i have a task No. in a data.frame
       Task_No       Team   
A    49397         1         
B    49396         1     

and now i want to match my Person-IDs to each Task_No. My Person Ids look
like this one:
    ID        Team
A 5019    1
B 472    1
C 140    1
D 5013    1

The solution should be this:

       Task_No       Team     ID
A    49397         1               5019
A    49397         1               472
A    49397         1               140
A    49397         1               5013
B    49396         1         5019
B    49396         1            472
B    49396         1            140
B    49396         1            5013

perhabs anyone can help me.

Thank you

Mat



--
View this message in context: http://r.789695.n4.nabble.com/match-a-task-No-to-a-few-person-IDs-tp4658646.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.
Reply | Threaded
Open this post in threaded view
|

Re: match a task No. to a few person-IDs

PIKAL Petr
In reply to this post by Mat
Hi

?merge

Regards
Petr

> -----Original Message-----
> From: [hidden email] [mailto:r-help-bounces@r-
> project.org] On Behalf Of Mat
> Sent: Friday, February 15, 2013 10:45 AM
> To: [hidden email]
> Subject: [R] match a task No. to a few person-IDs
>
> hello together,
>
> i have a task No. in a data.frame
>        Task_No       Team
> A    49397     1
> B    49396     1
>
> and now i want to match my Person-IDs to each Task_No. My Person Ids
> look like this one:
>     ID        Team
> A 5019 1
> B 472 1
> C 140 1
> D 5013 1
>
> The solution should be this:
>
>        Task_No       Team     ID
> A    49397     1           5019
> A    49397     1           472
> A    49397     1           140
> A    49397     1           5013
> B    49396     1     5019
> B    49396     1            472
> B    49396     1            140
> B    49396     1            5013
>
> perhabs anyone can help me.
>
> Thank you
>
> Mat
>
>
>
> --
> View this message in context: http://r.789695.n4.nabble.com/match-a-
> task-No-to-a-few-person-IDs-tp4658646.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.
Reply | Threaded
Open this post in threaded view
|

Re: match a task No. to a few person-IDs

Rui Barradas
In reply to this post by Mat
Hello,

Use ?merge.


tasks <- read.table(text = "
     Task_No       Team
A    49397     1
B    49396     1  
", header = TRUE)

ids <- read.table(text = "
     ID        Team
A 5019  1
B 472  1
C 140  1
D 5013  1
", header = TRUE)


merge(tasks, ids, all.x = TRUE)


Hope this helps,

Rui Barradas

Em 15-02-2013 09:45, Mat escreveu:

> hello together,
>
> i have a task No. in a data.frame
>         Task_No       Team
> A    49397     1
> B    49396     1  
>
> and now i want to match my Person-IDs to each Task_No. My Person Ids look
> like this one:
>      ID        Team
> A 5019 1
> B 472 1
> C 140 1
> D 5013 1
>
> The solution should be this:
>
>         Task_No       Team     ID
> A    49397     1           5019
> A    49397     1           472
> A    49397     1           140
> A    49397     1           5013
> B    49396     1     5019
> B    49396     1            472
> B    49396     1            140
> B    49396     1            5013
>
> perhabs anyone can help me.
>
> Thank you
>
> Mat
>
>
>
> --
> View this message in context: http://r.789695.n4.nabble.com/match-a-task-No-to-a-few-person-IDs-tp4658646.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.