Function to change value of a vector according to a manifest

Hello,
I have a vector of samples from a nomenclature A
I have a manifest.txt with another name for samples with a nomenclature B, which is a dataframe :

nomA <- c("AA1","AA2","AA3","AA4")
nomB <- c("BB1","BB2","BB3","BB4")
manifest <-data.frame(nomA,nomB)

I would like to turn my vector of samples in nomenclature A into nomenclature B.
I could use a loop, but the vector is too huge so I need to use a function, apply or other, which I don't find how to create.
Can someone help me ?

Regards

Simon

It is not clear to me what you are trying to accomplish can you share a sample of the desired output?

in input I have
vecA <- c("AA3","AA56","AA128","AA1256")

I have the manifest for corresponding name in nomenclature B from AA1 to AAx

I want an output as follows:
vecB <- c("BB3","BB56","BB128","BB1256")

it could be easily with a loop :

vecB = NULL
for (i in vecA) {
n <- manifest$nomB[which(manifest$nomA == vecA ) ]
vecB = c(vecB,n)
}

But vecA is very huge so I prefer to use a function, apply or other. I don't see how to code it.

Regards

Simon

This is an example using base R

manifest <- data.frame(
  stringsAsFactors = FALSE,
              nomA = c("AA1", "AA2", "AA3", "AA4"),
              nomB = c("BB1", "BB2", "BB3", "BB4")
)

vecA <- c("AA3","AA4")

vecB <- manifest[manifest$nomA %in% vecA, ]$nomB

vecB
#> [1] "BB3" "BB4"

Created on 2021-05-04 by the reprex package (v2.0.0)

Sorry for the delay, thank you !

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.