Add a index/Row number column to dataframe

0 votes
My dataset has only business related fields, but no index or row number, I want to add a index column, how to acheive this?
Aug 7 in Data Analytics by bharath
27 views

1 answer to this question.

0 votes

Hi, Bharath.

You can add index using seq(1:nrow(data frame)).

Example - 

mtcars %>% mutate(Id = seq(1:nrow(mtcars)))
matcars_new = mtcars %>% mutate(Id = seq(1:nrow(mtcars)))
answered Sep 10 by Cherukuri
• 32,260 points

Related Questions In Data Analytics

0 votes
1 answer
0 votes
2 answers
0 votes
1 answer

With the help of tidyverse: how to rename a column to a variable name

With the help of Dplyr: rename function ...READ MORE

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

edited Apr 3, 2018 by DeepCoder786 50 views
0 votes
1 answer

By using dpylr package sum of multiple columns

Basically here we are making an equation ...READ MORE

answered Apr 5, 2018 in Data Analytics by DeepCoder786
• 1,720 points
124 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
173 views
0 votes
1 answer

In a dpylr pipline how to use sample and seq?

For avoiding rowwise(), I prefer to use ...READ MORE

answered Apr 6, 2018 in Data Analytics by DeepCoder786
• 1,720 points
89 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
113 views
0 votes
3 answers

Code snippet to find number of null values in each column in a dataframe in R

colSums(is.na(data_frame_name)) will return you number of nulls ...READ MORE

answered Jul 5 in Data Analytics by sindhu
230 views
0 votes
2 answers

Locating row index of a column which has the maximum value - R

Hi, Nirvana You can also try this. which(iris$Sepal.Length == ...READ MORE

answered Aug 21 in Data Analytics by anonymous
• 32,260 points
145 views