Get data frame from character variable

Tomas Greif

I pass data frame name as string into a function. How do I get content of referenced data frame from the string? Suppose I have string 'mtcars' and I want to print data frame mtcars:

printdf <- function(dataframe) {
  print(dataframe)
}

printdf('mtcars');
A5C1D2H2I1M1N2O1R2T1

I think you'll need a get in there if the input is a string. Also, depending on your usage of the function, the explicit print might not be necessary:

printdf <- function(dataframe) {
  get(dataframe)
  # print(get(dataframe))
}
head(printdf("mtcars"))
#                    mpg cyl disp  hp drat    wt  qsec vs am gear carb
# Mazda RX4         21.0   6  160 110 3.90 2.620 16.46  0  1    4    4
# Mazda RX4 Wag     21.0   6  160 110 3.90 2.875 17.02  0  1    4    4
# Datsun 710        22.8   4  108  93 3.85 2.320 18.61  1  1    4    1
# Hornet 4 Drive    21.4   6  258 110 3.08 3.215 19.44  1  0    3    1
# Hornet Sportabout 18.7   8  360 175 3.15 3.440 17.02  0  0    3    2
# Valiant           18.1   6  225 105 2.76 3.460 20.22  1  0    3    1

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

as.character()应用于data.frame的单个元素与data.frame的整个“行”时

来自分类Dev

Unexpected output in converting numeric variable to a dummy variable in data frame - R

来自分类Dev

Building a data frame row by row from a list

来自分类Dev

python:How to print the character from a variable with unicode string

来自分类Dev

How to delete minority rows from a pandas data frame?

来自分类Dev

Extract original and duplicate result(s) from a data frame in R

来自分类Dev

Removing duplicates from pandas data frame with condition based on another column

来自分类Dev

Get/Set Workflow Variable from uiTypeEditor

来自分类Dev

Excel: Get max value from variable range

来自分类Dev

get.edgelist或get.data.frame将矩阵的值转换为边缘列表的权重

来自分类Dev

jQuery- How to get the GET variable from a URL

来自分类Dev

Putting functions into a data frame

来自分类Dev

读入data.frame

来自分类Dev

Subsetting character data in R

来自分类Dev

Get data from webpage using applescript

来自分类Dev

Get data from Smartwatch Android Wear to Smartphone

来自分类Dev

Get data from a specific column in a TableView QML

来自分类Dev

Get data from joined table in CakePHP

来自分类Dev

等价于Python igraph中的R igraph graph_from_data_frame()函数?

来自分类Dev

使用from和to字段将链拆分为data.frame

来自分类Dev

R中的data.frame(cbind ...)与data.frame(...)

来自分类Dev

FSharp R.data_frame

来自分类Dev

每天汇总data.frame

来自分类Dev

Subsetting data frame by factor level

来自分类Dev

Convert data frame to JSON in this format

来自分类Dev

data.frame或矩阵的散点图

来自分类Dev

Incremental IDs in a R data frame

来自分类Dev

快速创建data.frame

来自分类Dev

Data.frame 过滤使用 %in%

Related 相关文章

热门标签

归档