如何从矢量或矢量

时间:2016-08-11 15:21:33

标签: r dplyr

我有一个名字和一个载体

my.name <- 'data.values'
my.vec <- 1:5

我想制作一个tibble / tbl_df / data_frame,其中一列有my.name作为该列的名称,my.vec作为值。我拥有的是

df <- data_frame(placeholder = rep(NA, length(my.vec)))
df[[my.name]] <- my.vec
df[['placeholder']] <- NULL

这感觉很傻。有更简单的方法吗?

我也对我有多个向量和多个名称的情况感兴趣,例如

my.name1 <- 'data.values.day1'
my.name2 <- 'data.values.day2'
my.vec1 <- 1:5
my.vec2 <- 2:6
...

2 个答案:

答案 0 :(得分:2)

我认为最好的答案来自评论。

DirtySockSniffer建议:

Map

很好地概括了多列情况

as_data_frame(setNames(list(my.vec), my.name)))

答案 1 :(得分:0)

您可以先创建 public class WK_DecorrerObjetivo : CodeActivity { //inputs dialog --- // input alvo [Input("Alvo")] [ReferenceTarget("xpto_alvo")] public InArgument<EntityReference> alvo { get; set; } //input actividade xpto_atividadeobjetivoid [Input("Actividade Objetivo")] [ReferenceTarget("xpto_atividadedeobjetivo")] public InArgument<EntityReference> atividadeObjetivo { get; set; } protected override void Execute(CodeActivityContext Execontext) { ITracingService _tracing; IWorkflowContext context = null; IOrganizationServiceFactory serviceFactory = null; IOrganizationService service = null; OrganizationServiceContext serviceContext = null; try { #region Get Work Flow Context context = Execontext.GetExtension<IWorkflowContext>(); serviceFactory = Execontext.GetExtension<IOrganizationServiceFactory>(); service = serviceFactory.CreateOrganizationService(context.InitiatingUserId); serviceContext = new OrganizationServiceContext(service); _tracing = Execontext.GetExtension<ITracingService>(); _tracing.Trace("inicio do try"); FetchExpression query = new FetchExpression(string.Format(Resources.GetTemplateAtividade, context.PrimaryEntityId)); // Obtain result from the query expression. Entity new_alvo = (Entity)context.InputParameters["Target"]; var alvoGUID = ((EntityReference)new_alvo["xpto_alvo"]).Id; Entity retrieveTemp = service.Retrieve("xpto_alvo", ((EntityReference)new_alvo["xpto_alvo"]).Id, new ColumnSet("xpto_utilizador", "xpto_conta", "xpto_contacto", "xpto_alvoid", "xpto_name", "createdon", "xpto_estado", "xpto_resultadoimportacao", "xpto_objetivoassociadoid", "xpto_alvo")); OptionSetValue tipoAtividade = (OptionSetValue)retrieveTemp.Attributes["xpto_tipoatividade"]; switch (tipoAtividade.Value) { case 0: _tracing.Trace("entrou no case 0 - compromisso"); break; case 1: _tracing.Trace("entrou no case 1 - phonecall"); break; case 2: _tracing.Trace("entrou no case 2 - task"); break; default: break; } //serviceContext.SaveChanges(); _tracing.Trace("savechanges"); } catch (Exception ex) { string msgErro; if (ex.InnerException != null) { msgErro = ex.InnerException.Message; } else { msgErro = ex.Message; } throw new InvalidPluginExecutionException(string.Format("Erro ao decorrer objetivo: {0}", msgErro)); } } } ,然后设置其列名:

data_frame