How to add a new column to a Dataframe in R?

0 votes

Hi Team,

I have one Dataframe in R. I want to add one new column to this Dataframe. How can I do that?

Oct 30 in Data Analytics by akhtar
• 33,120 points
34 views

1 answer to this question.

0 votes

Hi@akhtar,

You can add new columns to a Dataframe using the $ and assignment <- operators. To do this, just use the df$name notation and assign a new vector of data to it. You can see the below-given example.

survey <- data.frame("index" = c(1, 2, 3, 4, 5), "age" = c(24, 25, 42, 56, 22))
survey$sex <- c("m", "m", "f", "f", "m")
answered Oct 30 by MD
• 78,020 points

Related Questions In Data Analytics

+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 13, 2018 in Data Analytics by Sahiti
• 6,320 points
1,229 views
0 votes
1 answer

How to limit output of a dataframe in R?

For randomly sampling a row/cell where a ...READ MORE

answered Apr 18, 2018 in Data Analytics by kappa3010
• 2,090 points
235 views
0 votes
1 answer

How to save a DataFrame in R??

Suppose your DataFrame is named as df: write.csv(df,file="exmp.csv") Then ...READ MORE

answered Apr 20, 2018 in Data Analytics by DeepCoder786
• 1,720 points
2,594 views
0 votes
1 answer

How to delete DataFrame row in pandas based upon a column value?

You can use drop function in your ...READ MORE

answered May 3, 2018 in Data Analytics by DeepCoder786
• 1,720 points

edited Jun 9 by MD 829 views
+10 votes
3 answers

Which is a better initiative to learn data science: Python or R?

Well it truly depends on your requirement, If ...READ MORE

answered Aug 8, 2018 in Data Analytics by Abhi
• 3,720 points
223 views
+1 vote
1 answer

Error saying "vector size cannot be NA" when using R with data mining

You can use the removesparseterm function.  Removes sparse ...READ MORE

answered Nov 15, 2018 in Data Analytics by Maverick
• 10,820 points
1,620 views
+1 vote
2 answers
0 votes
1 answer

Trying to find frequent itemsets of a data set using arules package

Try replacing ID <- c("A123","A123","A123","A123","B456","B456","B456") item <- c("bread", "butter", "milk", ...READ MORE

answered Nov 15, 2018 in Data Analytics by Maverick
• 10,820 points
122 views
0 votes
1 answer
0 votes
1 answer

How to extract specific columns from a dataframe in R?

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

answered Aug 7 in Data Analytics by MD
• 78,020 points
120 views