14
兩個例子對我很有幫助。如何選擇名稱中包含特定字符串的R數據框中的變量?
我將如何選擇: 1)變量,其名稱以B或B(即不區分大小寫) 或 2)變量,其名稱包含3
df <- data.frame(a1 = factor(c("Hi", "Med", "Hi", "Low"),
levels = c("Low", "Med", "Hi"), ordered = TRUE),
a2 = c("A", "D", "A", "C"), a3 = c(8, 3, 9, 9),
b1 = c(1, 1, 1, 2), b2 = c(5, 4, 3,2), b3 = c(3, 4, 3, 4),
B1 = c(3, 6, 4, 4))