R打印向量的一个元素

R打印向量的一个元素,r,vector,printing,element,R,Vector,Printing,Element,这是一个编程问题。我不知道如何打印出向量的1个元素。我的代码如下: # creating a range of values to test for accuracy thresh=seq(0,1,by=0.05) acc = matrix(0,1,20) # computing accuracy for different threshold values from 0 to 1 step by 0.05 for (i in 1:21){ matrix = confusion.matrix

这是一个编程问题。我不知道如何打印出向量的1个元素。我的代码如下:

# creating a range of values to test for accuracy
thresh=seq(0,1,by=0.05)
acc = matrix(0,1,20)
# computing accuracy for different threshold values from 0 to 1 step by 0.05
for (i in 1:21){
  matrix = confusion.matrix(obs,pred,threshold=thresh[i])
  acc[i]=(matrix[1,1]+matrix[2,2])/nrow(test)
  acc[i]}
max(acc)
library(nnet)
which.is.max(acc)
acc
#Q how can I print only thresh[12] the first max(acc)? 
   there may be more than one thresh with the max(acc).
print(thresh)

如果我理解你的要求,这应该行得通。这里有一个简单的例子

a <- c(1,2,3,3)
thresh <- c(1,2,3,4)

# run at command line
> thresh[a==max(a)]
  [1] 3 4

a如果我理解你的要求,这应该行得通。这里有一个简单的例子

a <- c(1,2,3,3)
thresh <- c(1,2,3,4)

# run at command line
> thresh[a==max(a)]
  [1] 3 4

简单的问题,简单的答案。简单的问题,简单的答案。