简体   繁体   English

将数据集中的元素作为列名传递

[英]have an element in data set be passed as a column name

I need to get names from one data set that are the names columns in a second data set, but when I try to it say the second data set is NULL. 我需要从一个数据集中获取名称,该名称是第二个数据集中的名称列,但是当我尝试说第二个数据集为NULL时。 For example wanting to grad "colors" form the var_list, and applied it to the full data set with the column name "color".I have made it so that the values in the var_list data set have the same names as column names in the full data set. 例如,要从var_list分级“颜色”,并将其应用于列名称为“ color”的完整数据集。我这样做是为了使var_list数据集中的值具有与列名相同的名称。完整的数据集。

z <- var_list$var[1] 

print(z)

colors

full_data$z 

Null

You could do this with names inside [] : 您可以使用[] names来完成此操作:

var_list <- data.frame(var="colors",other="any",stringsAsFactors=FALSE)
full_data <- data.frame(colors=1:4, o=1:2)
z <- var_list$var[1]

full_data[names(full_data)==z]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM