Re: [R] How to obtain named vector from single-column data frame?

2022-05-06 Thread Hooiveld, Guido
Dear David and Rui, Thanks a lot to both of you for your very fast answers; problem solved! :) Regards, Guido From: David Carlson Sent: 06 May 2022 20:26 To: Hooiveld, Guido Cc: r-help@r-project.org Subject: Re: [R] How to obtain named vector from single-column data frame? Just use names

Re: [R] How to obtain named vector from single-column data frame?

2022-05-06 Thread David Carlson via R-help
Just use names(unlist(df[, "VarY", drop=FALSE])) # [1] "VarY1" "VarY2" "VarY3" "VarY4" "VarY5" When you extract a single column from a data frame it converts it to a vector by default. David L Carlson On Fri, May 6, 2022 at 1:05 PM Hooiveld, Guido wrote: > Dear all, I wrote a some code in wh

Re: [R] How to obtain named vector from single-column data frame?

2022-05-06 Thread Rui Barradas
Hello, When you unlist, the dimension is dropped since the result is just one vector. Add drop = FALSE and that's it. unlist(df[, "VarY", drop = FALSE]) Hope this helps, Rui Barradas Às 19:05 de 06/05/2022, Hooiveld, Guido escreveu: Dear all, I wrote a some code in which I 'convert' a d