TransWikia.com

Append and replacing data in r

Data Science Asked by Xingqi Fei on January 11, 2021

I am writing a few lines of codes to create a data table full of NAs but don’t know how to append the data of results into the data table I created while replacing the position of NAs.
Here is my data table
enter image description here

games<-10
game_results<-as.data.frame(matrix(NA,games,3))
install.packages("data.table")
library(data.table)
setnames(game_results,c("V1","V2","V3"),c("winner","round","winnerscore"))
game_results

One Answer

You could change in this case with command

game_results$winner[1] <- "Dad"

But this copies the whole table, so i will recomend you to create an empty data in another way

game_results <- setNames(data.table(matrix(nrow = 10, ncol = 3)), c("winner","round","winnerscore"))

and assignment by reference in the way you prefer (hole column or specific cell), here instructions for both cases.

Answered by Danyl Denysenko on January 11, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP