如果您不喜欢这种行为,则可以使用"[["运算符.它带有参数exact=,该参数允许您控制部分匹配行为,并且默认为TRUE.wtf[["whatisthep"]] # Only returns exact matches# NULLwtf[["whatisthep", exact=FALSE]] # Returns partial matches without warning# [1] 2wtf[["whatisthep", exact=NA]] # Returns partial matches & warns that it did# [1] 2# Warning message:# In wtf[["whatisthep", exact = NA]] :# partial match of 'whatisthep' to 'whatisthepointofthis'(这是为什么R编程中通常首选"[["优于$的一个原因.另一个原因是能够执行此X <- "whatisthe"; wtf[[X]]而不是执行此X <- "whatisthe"; wtf$X的能力.)This got me pretty bad. You can abbreviate list names? I never noticed it before and I got totally screwed for like a day. Can someone explain what is happening here and why it could be more useful than it is terrible? And why its inconsistent like that at the bottom? And if I can turn it off?> wtf <- list(whatisthe=1, pointofthis=2) > wtf$whatisthe [1] 1 > wtf$what [1] 1 > wtf <- list(whatisthe=1, whatisthepointofthis=2) > wtf$whatisthepointofthis [1] 2 > wtf$whatisthep [1] 2 > wtf$whatisthe [1] 1 > wtf$what NULL 解决方案 I suspect that partial matching by the $ operator was a nice(r) feature for interactive use back in the days before tabbed completion had been implemented If you don't like that behavior, you can use the "[[" operator instead. It takes an argument exact=, which allows you to control partial matching behavior, and which defaults to TRUE.wtf[["whatisthep"]] # Only returns exact matches# NULLwtf[["whatisthep", exact=FALSE]] # Returns partial matches without warning# [1] 2wtf[["whatisthep", exact=NA]] # Returns partial matches & warns that it did# [1] 2# Warning message:# In wtf[["whatisthep", exact = NA]] :# partial match of 'whatisthep' to 'whatisthepointofthis'(This is one reason why "[[" is generally preferred to $ in R programming. Another is the ability to do this X <- "whatisthe"; wtf[[X]] but not this X <- "whatisthe"; wtf$X.) 这篇关于您可以缩写列表名称吗?为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 10-10 12:18