Julie
Julie

Reputation: 19

How to get corresponding value in two data frame

I have one file:

File_A:

ID  C1.x    C2.x    C3.x    C4.x    C5.x
M1  60  32  19  25  5
M2  5   14  12  15  5
M3  51  2   2   8   8
M4  15  8   8   8   7
M5  12  86  7   8   9

File_B:

ID  C1.y    C2.y    C3.y    C4.y    C5.y
M1  N   K   K   K   N
M2  M   M   M   M   M
M3  Y   T   T   T   T
M4  A   A   A   A   A
M5  C   C   N   C   C

Filter is 5. if less than 5, then corresponding columns should become N.

Thanks

Upvotes: 0

Views: 51

Answers (1)

Joel Carlson
Joel Carlson

Reputation: 640

If everything lines up properly, you can simply use:

#Test data
dat <- data.frame("ID"=c("M1","M2", "M3", "M4", "M5"), "C1.x"=c(60,5,51,15,12), "C2.x"=c(32,14,2,8,86), "C3.x"=c(19,12,2,8,7), stringsAsFactors=FALSE)
dat2 <- data.frame("ID"=c("M1","M2", "M3", "M4", "M5"), "C1.x"=c("N", "M", "Y", "A", "C"), "C2.x"=c("N", "M", "Y", "A", "C"), "C3.x"=c("N", "M", "Y", "A", "C"), stringsAsFactors=FALSE)

dat2[dat < 5] <- "N"

I think that's the output you are looking for. If not, please clarify.

Upvotes: 1

Related Questions