[R] substitute column data frame based on name stored in variable in r
drj|m|emon @end|ng |rom gm@||@com
Mon Aug 9 10:53:29 CEST 2021
It looks to me as though you will have to copy the data frame or store
the output in a new data frame.
On Mon, Aug 9, 2021 at 6:26 PM Luigi Marongiu <marongiu.luigi using gmail.com> wrote:
> I would like to recursively select the columns of a dataframe by
> strong the names of the dataframe in a vector and extracting one
> element of the vector at a time. This I can do with, for instance:
> vect = names(df)
> The problem is that I would like also to change the values of the
> selected column using some logic as in `df$column[df$column == value]
> <- new.value`, but I am confused on the syntax for the vectorized
> version. Specifically, this does not work:
> sub_df[vect == 0] = "No"
> What would be the correct approach?
> Thank you
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
More information about the R-help