I have a df that looks like the on the left. I would like to put all rows inputs into one row,and still keep old rows. How should I do this?
df<-structure(list(c1 = c("Student Enrollment", "750"), c2 = c("Faculty Number",
"21"), c3 = c("Graduated", "65")), row.names = c(NA, -2L), class = c("tbl_df",
"tbl", "data.frame"))
>Solution :
output = rbind(df, lapply(df, paste, collapse = "\n"))
output
# c1 c2 c3
# 1 Student Enrollment Faculty Number Graduated
# 2 750 21 65
# 3 Student Enrollment\n750 Faculty Number\n21 Graduated\n65
In the console, line breaks print as \n. If you View() it they will print as spaces. There are probably some nice table formatting packages that actually display linebreaks within a cell.
You could, of course, replace "\n" in my code with " " to use a space instead of a linebreak.
