How do I know if my data in R is a list or a data.frame?
我怎么知道R中的数据是列表还是data.frame?
If I use typeof(x)
it says list, if I use class(x)
it says data.frame?
如果我使用typeof(x)它表示列表,如果我使用class(x)它表示data.frame?
1 个解决方案
#1
6
To clarify a possible misunderstanding given the title of your question, a data.frame
is also a list.
为了澄清给出问题标题可能存在的误解,data.frame也是一个列表。
is.list(data.frame()) # TRUE
However, you can use inherits()
to see if an object is a list
or data.frame
但是,您可以使用inherits()来查看对象是列表还是data.frame
inherits(data.frame(), "data.frame") # TRUE
inherits(list(), "data.frame") # FALSE
inherits(data.frame(), "list") # FALSE
inherits(list(), "list") # TRUE
#1
6
To clarify a possible misunderstanding given the title of your question, a data.frame
is also a list.
为了澄清给出问题标题可能存在的误解,data.frame也是一个列表。
is.list(data.frame()) # TRUE
However, you can use inherits()
to see if an object is a list
or data.frame
但是,您可以使用inherits()来查看对象是列表还是data.frame
inherits(data.frame(), "data.frame") # TRUE
inherits(list(), "data.frame") # FALSE
inherits(data.frame(), "list") # FALSE
inherits(list(), "list") # TRUE