I have data as follows:
dat <- structure(
list(
freq = list(a= c(5, 38, 43, 27, 44, 20, 177), b=c(3, 5, 12, 53, 73))),
row.names = c(NA, -2L), class = "data.frame")
I would like to do two things:
- Remove the last item of each list
- Append the string values
"Infinity"and"SUM"
Normally one could do
x <- c(1,2,3)
x <- x[-length(x)]
x <- append(x, c("Infinity", "SUM"))
But how does that work if these vectors are in a list?
Desired output:
dat_out <- structure(
list(
freq = list(a= c(5, 38, 43, 27, 44, 20, "Infinity", "SUM"), b=c(3, 5, 12, 53, "Infinity", "SUM"))),
row.names = c(NA, -2L), class = "data.frame")