text - Replacing words within a matrix in R -
i have matrix. single data entry in matrix character string. example, "crocin tablet". matrix contains many entries "tablet" @ end. want replace word "tablet" "tab" every entry within matrix. how can in r?
just making ananda mahto's solution more explicit.
> newmatrix <- matrix(data=c("abbott laboratories tablet", + "abbvie tablet", + "acadia pharmaceuticals tablet", + "acorda therapeutics tablet", + "actavis tablet", + "actelion tablet", + "advanced chemical industries tablet", + "advaxis tablet", + "ajanta pharma tablet", + "alcon tablet"), nrow=5, ncol = 2) > gsub("tablet", "tab", newmatrix) [,1] [,2] [1,] "abbott laboratories tab" "actelion tab" [2,] "abbvie tab" "advanced chemical industries tab" [3,] "acadia pharmaceuticals tab" "advaxis tab" [4,] "acorda therapeutics tab" "ajanta pharma tab" [5,] "actavis tab" "alcon tab"
Comments
Post a Comment