How to extract specific columns from a dataframe in R

0 votes

Hi Guys,

I am new in R. I have one data frame in R. I want to extract some specific columns from that data frame. How can I do that?

Aug 7, 2020 in Data Analytics by akhtar
• 38,260 points
1,949 views

1 answer to this question.

0 votes

Hi@akhtar,

You can use the select method to extract any columns from a data frame. I have attached one example below for your reference.

> df
  IND snp1 snp2 snp3 snp4 snp5
1   1  A/G  T/T  T/C  G/C  G/G
2   2  A/A  C/C  G/G  G/G  A/A
3   3  T/T  G/G  C/C  C/C  T/T

This is a data frame that has six columns. Now to extract particular columns we can use the select method.

> select(df, snp1,snp3,snp4)
  snp1 snp3 snp4
1  A/G  T/C  G/C
2  A/A  G/G  G/G
3  T/T  C/C  C/C
answered Aug 7, 2020 by MD
• 95,460 points

Related Questions In Data Analytics

0 votes
1 answer

How to extract specific columns from a DataFrame ?

Yes there are so many ways: df[,c(V2,V4)] and another ...READ MORE

answered Apr 11, 2018 in Data Analytics by DeepCoder786
• 1,720 points
8,666 views
0 votes
1 answer
0 votes
1 answer
+1 vote
1 answer

How to convert a list of dataframes in to a single dataframe using R?

You can use the plyr function: data <- ...READ MORE

answered Apr 14, 2018 in Data Analytics by Sahiti
• 6,370 points
7,037 views
0 votes
1 answer

How to convert a text mining termDocumentMatrix into excel or csv in R?

By assuming that all the values are ...READ MORE

answered Apr 5, 2018 in Data Analytics by DeepCoder786
• 1,720 points
1,919 views
0 votes
1 answer

How to create a list of Data frames?

Basically all we have to do is ...READ MORE

answered Apr 9, 2018 in Data Analytics by DeepCoder786
• 1,720 points
1,339 views
0 votes
1 answer

How to spilt a column of a data frame into multiple columns

it is easily achievable by using "stringr" ...READ MORE

answered Apr 9, 2018 in Data Analytics by DeepCoder786
• 1,720 points
1,774 views
+1 vote
2 answers

How to sort a data frame by columns in R?

You can use dplyr function arrange() like ...READ MORE

answered Aug 21, 2019 in Data Analytics by anonymous
• 33,030 points
1,812 views
0 votes
1 answer
0 votes
1 answer

How to select columns containing specific text in R?

Hi, You can use the select method to extract ...READ MORE

answered Aug 7, 2020 in Data Analytics by MD
• 95,460 points
3,306 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP