Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个清单:
>data<- list("Apple"=12,"orange"=4,"pear"=5) >fruit<- "Apple"
现在我提取苹果的价值。
>data$fruit
我得到NULL。
data<- list("Apple"=12,"orange"=4,"pear"=5) fruit<- "Apple" data[fruit] #$Apple #[1] 12 data[[fruit]] #[1] 12
如您所见[,返回一个列表,而[[返回向量。前者可以选择多个元素,而后者只能选择一个元素。你可能会从阅读中受益?"$"。
[
[[
?"$"