R
Error in sum(List) : invalid ‘type’ (list) of argument, sum()
Ninestar
2022. 12. 14. 13:34
반응형
리스트 만들어주고
List <- list(1:10, 15, 100) List [[1]] [1] 1 2 3 4 5 6 7 8 9 10 [[2]] [1] 15 [[3]] [1] 100
리스트를 합계 내보려는데 에러가 뜬다.
sum(List) Error in sum(List) : invalid 'type' (list) of argument sum(unlist(listvec)) 170
we must first use the unlist function to transform our list into a vector object.
R에서는 List 형식은 sum이 안된다.
dplyr %>%에서도 데이터프레임 컬럼 내용인데 summarise(sum(컬럼명))을 해도 에러가 났다.

unlist로 리스트를 벡터로 변환해주니 sum이 제대로 작동한다.
