Error: invalid subscript type ‘list’ in R

We need to use concatenate to create a vector instead of list

x <- c("alpha", "beta")
rowSums(d[x])
#[1] 5 7 9

and if we are using list, then unlist it to create a vector as data.frame takes a vector of column names (column index) or row names (row index) to subset the columns or rows

x <- list("alpha", "beta")
rowSums(d[unlist(x)])
#[1] 5 7 9

Leave a Comment

tech