I am trying to accomplish the following task in R.
(1) sum over the columns that are numeric
(2) given two numbers, tell me the column numbers and/or names of the columns whose column sums are within that range, inclusive
Example: I would like to sum the columns of the following data frame but there is unfortunately a column of characters causing apply to fail. Afterward, I would like to retrieve the column index of the columns that had sums between 655 and 855.
dat=data.frame(matrix(1:100, nrow=10), matrix(LETTERS[1:10], nrow=10)) apply(dat, 2, sum) sum(dat[,7]) sum(dat[,9])
https://stackoverflow.com/questions/66084399/sum-over-numeric-columns-and-report-indices-of-column-sums-that-lie-within-a-spe February 07, 2021 at 11:54AM
没有评论:
发表评论