gpt4 book ai didi

r - 用字符串指定的名称保存R数据帧

转载 作者:行者123 更新时间:2023-12-04 09:37:26 24 4
gpt4 key购买 nike

在这个很棒的论坛上,我看到了一篇帖子,展示了如何将字符串转换为变量并将数据帧分配给该变量。例如:

x =“thisisthestring”

# df is a data frame
assign(x, df) # This will assign data frame df to variable thisisthestring

我想做的就是用 thisisthestring名称保存该数据框。但是,如果我尝试
assign(x, df)
save(x, file='somefilename.rda')

该文件仅包含字符串“thisisthestring”,而不包含数据帧df。

我也试过了
save(assign(x, df), file = 'somefile.rda'))

那也不行。关于如何将数据框保存到文件的任何建议,其中数据框的名称由字符串指定。

最佳答案

xlist添加到save()参数中。从帮助文件中:

list A character vector containing the names of objects to be saved.


save(list=x, file='somefilename.rda') 

关于r - 用字符串指定的名称保存R数据帧,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6318186/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com