[R] add specific fields in for loop

Bert Gunter bgunter@4567 @end|ng |rom gm@||@com
Tue Nov 15 18:08:43 CET 2022


There is no function columns() in base R.
Is 'date' an object that contains column names or indices? Or do you mean
that it is a string that appears in the column names you wish to loop over?

A small reprex should be easy to provide to show us explicitly what you
want. Please do so -- unless, of course, someone with greater insight than
I provides you a satisfactory answer.

Cheers,
Bert

On Tue, Nov 15, 2022 at 8:19 AM Kai Yang via R-help <r-help using r-project.org>
wrote:

> Hi Team,
> I can write a for loop like this:
> for (i in columns(df)){
>   ......
> }
>
> But it will working on all column in dataframe df. If I want to work on
> some of specific fields (say: the fields' name content 'date'), how should
> I modify the for loop? I changed the code below, but it doesn't work.
> for (i in columns(df) %in% 'date' ){
>   .....
> }
>
>
> Thank you,
> Kai
>
>         [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

	[[alternative HTML version deleted]]



More information about the R-help mailing list