In R, come si aggiunge una nuova riga a un frame di dati una volta che il frame di dati è già stato inizializzato?
Finora ho questo:
df <- data.frame("hi", "bye")
names(df) <- c("hello", "goodbye")
#I am trying to add "hola" and "ciao" as a new row
de <- data.frame("hola", "ciao")
merge(df, de) # Adds to the same row as new columns
# Unfortunately, I couldn't find an rbind() solution that wouldn't give me an error
Qualsiasi aiuto sarebbe apprezzato
rbind(df, setNames(de, names(df)))
rbind(data.frame(a = 1), data.frame(b = 2))... perché dovresti farlo? Spero che ciò provocherebbe un errore a prescindere. È come merge'ing con una byvariabile casuale . E questo è il 2015, non sono tutti pronti options(stringsAsFactors = FALSE)?
stringsAsFactors=FALSEpuò essere una soluzione rapida, ma cambiare le impostazioni predefinite che altre persone hanno impostato in modo diverso può davvero rovinare un giorno.
deanche a.names(de) <- c("hello","goodbye")erbind