[英]R: Extract Rows from One Data Frame, Based on Column Names Matching Values from Another Data Frame
[英]Extract column names from data frame based on cell value in R
嗨,我有一個這樣的數據框:
location = c("100 ail","16th and Whitmore","40AB01 - ANTWERPEN")
lastUpdated = c("2018-02-01 09:30:00", "2018-02-01 03:00:00", "2017-03-07 10:00:00")
firstUpdated = c("2015-09-01 00:00:00","2016-03-06 19:00:00","2016-11-22 15:00:00")
pm25=c("FALSE","FALSE","FALSE")
pm10=c("TRUE","FALSE","FALSE")
no2=c("TRUE","FALSE","FALSE")
latitude=c(47.932907,41.322470,36.809700)
longitude=c(106.92139000,-95.93799000
,-107.65170000)
df = data.frame(location, lastUpdated, firstUpdated,latitude,longitude,pm25,pm10,no2)
我想提取具有value =“ TRUE”的第一行的名字。 我試過了:
colnames(df[1,6:8]=="TRUE")
但沒有成功。
你必須使用的功能which
以提取等於TRUE列
colnames(df[,6:8][,which(df[1,6:8]=="TRUE")])
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.