Add New Row at Specific Index Position to Data Frame in R (Example) | rbind & rownames Functions

preview_player
Показать описание
R code of this video:

x2 = 11:15,
x3 = 21:25)

new_row <- c(9, 99, 999) # Create example row
new_row # Print example row

data_new <- rbind(data[1:3, ], # Applying rbind function
new_row,
data[- (1:3), ])

rownames(data_new) <- 1:nrow(data_new) # Modify row names

Follow me on Social Media:
Рекомендации по теме
Комментарии
Автор

Great video!! I really appreciate that your tutorials show things that are going to be useful yet many other tutorials do not include them.

agsoutas
Автор

Great Video !!!
I have a question. I have the price data for a share, but at some of the 30 years, there is no row for the 1.1.x .
Is there an option to add the row for all the year, where there is no row for the 1.1.x?
your solution in the video is a "little" bit too much code for all the years?

franz