Match row value with column name and extract value in R

后端 未结 2 1139
日久生厌
日久生厌 2020-12-19 13:07

I have a table where I need to choose all the values in the Data column, match with the column names and take the value from that row. Ex. Data column: choose A1, find colu

2条回答
  •  有刺的猬
    2020-12-19 13:41

    What about this?

    df[cbind(1:4, match(df$Data, names(df)))]
    [1] "1"  "6"  "11" NA
    

提交回复
热议问题