ect: Re: [R] column means dropping column minimum
First, your code has flaws in the assignment of NA and in passing na.rm=TRUE to
colMeans().
It should be:
test2 <- test
for (i in 1:ncol(test)) { test2[which.min(test[,i]),i]=NA}
print(test2)
samp1 samp2 samp3
16060NA
250
First, your code has flaws in the assignment of NA and in passing na.rm=TRUE to
colMeans().
It should be:
test2 <- test
for (i in 1:ncol(test)) { test2[which.min(test[,i]),i]=NA}
print(test2)
samp1 samp2 samp3
16060NA
2506065
3NA9065
490NA90
There is a bug in your code: it is not
> for (i in 1:ncol(test)) { test2[which.min(test[,i]),i]==NA}
but
for (i in 1:ncos(test)) {
test2[which.min(test[, i]), i] <- NA
}
Otherwise, a solution would be to create your own function to compute the mean
of a vector without the smallest value:
me
Suppose I have something like the following dataframe:
samp1 <- c(60,50,20,90)
samp2 <- c(60,60,90,58)
samp3 <- c(25,65,65,90)
test <- data.frame(samp1,samp2,samp3)
I want to calculate column means. Easy enough, if I want to use all the
data within each column:
print(colMeans(test),na.rm =
4 matches
Mail list logo