0
$\begingroup$

Please I'm a beginner in using R and I work on database.

I have a database that contain lot of columns and lines, like this for example

Column1   Column2 
5            T1
1            T2
1            T3
1            T1
2            T1
1            T1
2            T1
1            T1

I want to extract just lines that have the value 1 in column 1 and Value T1 in Column 2

So the result I want is

Column1   Column2 
1            T1
1            T1
1            T1

Can you tell me please how I can do that

Thank you very much

$\endgroup$
4
  • $\begingroup$ Hi @James what code have you written so far? You must have imported into R and done some basic dataframe work. $\endgroup$
    – M__
    Dec 20 '20 at 19:16
  • $\begingroup$ Hello , thank you very much for you answer , yes i tried this one : Pokemon_2 <- dropRows(ds, Pokemon$Generation == 1 , Pokemon$Type_1=="Water" ) but it didn't work , Error in dropRows(ds, Pokemon$Generation == 1, Pokemon$Type_1 == "Water") : could not find function "dropRows" $\endgroup$
    – James
    Dec 20 '20 at 20:08
  • $\begingroup$ You should look at the subset function. Please google "filter data frame by column value" - much like writing for loops in basic programming languages, it is a basic operation that does not warrant creating new posts on forums. $\endgroup$
    – Ram RS
    Dec 20 '20 at 20:27
  • $\begingroup$ I’m voting to close this question because it is a basic R operation has nothing to do with bioinformatics specifically $\endgroup$
    – Ram RS
    Dec 20 '20 at 20:28
1
$\begingroup$

You can simply use subset function in R and use the code given below,

    new_dataframe <- 
    subset(name_of_your_dataframe,Column1 == 1 && 
    Column2 ==  "T1")

Please keep in mind that R is case sensitive and you should be careful while using the variable names.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.