Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in R Programming by (50.2k points)
edited by

I want to fill the value of pca.data$Type with 'DMSO' but the condition is that if the 'DMSO' is present in the column of pca.data$sample in R.

pca.data$Type[pca.data$sample %in% "DMSO"]='DMSO'

The following is my sample data:

SampleType
BEL5438.DMSO.1DMSO
BEL5438.DMSO.2DMSO
BEL5438.DMSO.3DMSO
BEL5438.JQ1.1JQ1
BEL5438.JQ1.2JQ1
BEL5438.JQ1.3JQ1
HCCC6478.DMSO.1DMSO
HCCC6478.DMSO.2DMSO
HCCC6478.DMSO.3DMSO

 

 

1 Answer

0 votes
by (108k points)

You can simply use the following code for getting your desired output.

pca.data$Type[grep("DMSO", pca.data$sample)] = "DMSO"

If you are a beginner and want to know more about R, then do checkout the following R programming tutorial that will help you in understanding the basics of R. 

Browse Categories

...