簡體   English   中英

將 R 中 data.frame 的名稱提取為字符

[英]Extract name of data.frame in R as character

如何將 R 中的data.frame的名稱提取為字符?

例如,如果我有名為df data.frame ,我想將“df”作為字符對象。

a <- data.frame()
deparse(substitute(a))
[1] "a"

這也是plot如何知道在軸上放什么

如果您有多個要檢索其名稱的數據ls.str(mode = "list") ,則可以使用ls.str(mode = "list") 我們使用列表是因為數據幀存儲為列表。

例如:

# make two dataframes
mydf1 <- data.frame(a = letters[1:10], b = runif(10))
mydf2 <- data.frame(a = letters[1:10], b = runif(10))

# see that dataframes are stored as lists:
storage.mode(mydf1)
[1] "list"

# store the names of the dataframes
names_of_dataframes <- ls.str(mode = "list")

# see the name of the first dataframe
names_of_dataframes[1]
[1] "mydf1"

# see the name of the second dataframe
names_of_dataframes[2]
[1] "mydf2"

請注意,此方法還將包括全局環境中其他列表對象的名稱。 ls.str允許您選擇要搜索的環境,以便您可以將數據幀存儲在與其他列表對象不同的環境中。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM