将Hlookup与Choose()数组一起使用

时间:2018-04-05 12:11:10

标签: excel excel-formula

我正在尝试使用带有“Choose()”函数的Hlookup作为数组。它与vlookup完美配合,如下所示:

server<- shinyServer(function(input,output) {

  ## input$file is a data frame and contains the details around the name, size and temp location of the files uploaded
  # this reactive output display the content of the input$file dataframe
  output$filedf <- renderTable({
    if(is.null(input$file)){return ()}
    input$file # the file input data frame object that contains the file attributes
  })

  # Extract the file path for file
  output$filedf2 <- renderTable({
    if(is.null(input$file)){return ()}
    input$file$datapath # the file input data frame object that contains the file attributes
  })

  ## Below code to display the structure of the input file object
  output$fileob <- renderPrint({
    if(is.null(input$file)){return ()}
    str(input$file)
  })

  ## Side bar select input widget coming through renderUI()
  # Following code displays the select input widget with the list of file loaded by the user
  output$selectfile <- renderUI({
    if(is.null(input$file)) {return()}
    list(hr(), 
         helpText("Select the files for which you need to see data and summary stats"),
         selectInput("Select", "Select", choices=input$file$name)
    )

  })

  ## Summary Stats code ##
  # this reactive output contains the summary of the dataset and display the summary in table format
  output$summ <- renderPrint({
    if(is.null(input$file)){return()}
    summary(read.csv(file=input$file$datapath[input$file$name==input$Select], 
                       sep=input$sep, 
                       header = input$header, 
                       stringsAsFactors = input$stringAsFactors))})

  ## Dataset code ##
  # This reactive output contains the dataset and display the dataset in table format
  output$table <- renderTable({ 
    if(is.null(input$file)){return()}
    read.csv(file=input$file$datapath[input$file$name==input$Select], sep=input$sep, header = input$header, stringsAsFactors = input$stringAsFactors)

  })

  ## MainPanel tabset renderUI code ##
  # the following renderUI is used to dynamically generate the tabsets when the file is loaded. 
  # Until the file is loaded, app will not show the tabset.
  output$tb <- renderUI({
    if(is.null(input$file)) {return()}
    else
      tabsetPanel(
        tabPanel("Input File Object DF ", tableOutput("filedf"), tableOutput("filedf2")),
        tabPanel("Input File Object Structure", verbatimTextOutput("fileob")),
        tabPanel("Dataset", tableOutput("table")),
        tabPanel("Summary Stats", verbatimTextOutput("summ")))
  })
})
shinyApp(ui, server)


ui <- shinyUI(fluidPage(
  titlePanel("Claim Model"),
  sidebarLayout(
    sidebarPanel(
      numericInput("1"),
    ),
    mainPanel(
      textOutput('dynamicText')
    )
    )
  )
)

enter image description here

为什么它不能用于Hlookup,如下所示:

=VLOOKUP(1;CHOOSE({1,2};A1:A3;C1:C3);2;FALSE)

enter image description here

注意:我正在尝试修复我的excel公式,因此不需要VBA。

1 个答案:

答案 0 :(得分:3)

因为您的数组是水平的。您需要更改分隔符。

您可以将数组{1,2}视为以下范围:

  

| 1 | 2 |

这意味着CHOOSE({1,2},A1:A3,C1:C3)可被视为:

  

| =A1:A3 | =C1:C3 |
  或
  | =A1 | =C1 |
  | =A2 | =C2 |
  | =A3 | =C3 |

你在VLOOKUP上找到=A3,然后查看第二列:=C3

现在,这也意味着CHOOSE({1,2},A1:C1,A3:C3)可以表示为 this

  

| =A1:C1 | =A3:C3 |
  或
  | =A1 | =B1 | =C1 | =A3 | =B3 | =C3 |

对此进行HLOOKUP,找到=C1,然后......嗯,不是第二行。

这意味着我们需要一种方法来代表这个

  

| =A1:C1 |
  | =A3:C3 |
  或
  | =A1 | =B1 | =C1 |
  | =A3 | =B3 | =C3 |

因为您找到了=C1,请查看第二个,然后获取=C3

嗯,我们怎么做?简单!我们只需将{1,2}更改为{1;2},因为它代表

  

| 1 |
  | 2 |

代替:

=HLOOKUP(1;CHOOSE({1;2};A1:C1;A3:C3);2;FALSE)



(顺便说一句,这意味着{1,2;3,4}成为以下内容:)

  

| 1 | 2 |
  | 3 | 4 |