[R] show structure of selected columns of dataframe

Luigi Marongiu m@rong|u@|u|g| @end|ng |rom gm@||@com
Wed Sep 15 18:47:16 CEST 2021


Thanks

On Wed, Sep 15, 2021 at 5:12 PM Jeff Newmiller <jdnewmil using dcn.davis.ca.us> wrote:
>
> Really?
>
> str( df[ , grep(".*_a*.", names(df)) ] )
>
>
> On September 15, 2021 7:53:17 AM PDT, Luigi Marongiu <marongiu.luigi using gmail.com> wrote:
> >Hello,
> >I have a dataframe and I would like to browse the information of its
> >structure only for a subset of columns (since there are hundreds of
> >them).
> >For instance, I tried with grepping some columns as in:
> >```
> >df <- data.frame(var_a1 = c(letters[1:3], letters[1:4]),
> >                 var2 = c(LETTERS[1:7]),
> >                 var_a2 = c(letters[1:3], letters[1:4]),
> >                 var4 = (1:7)^2,
> >                 var_a3 = c("light", "light", "heavy", "heavy", "heavy",
> >                          "light", "heavy"),
> >                 stringsAsFactors = FALSE)
> >> grep("*._a*.", names(df))
> >[1] 1 3 5
> >```
> >This tells me that the pattern v_1 is present in the name of columns 1 3 5.
> >Would it be possible to get a str() of just these columns?
> >
> >```
> >> str(df)
> >'data.frame': 7 obs. of  5 variables:
> > $ var_a1: chr  "a" "b" "c" "a" ...
> > $ var2  : chr  "A" "B" "C" "D" ...
> > $ var_a2: chr  "a" "b" "c" "a" ...
> > $ var4  : num  1 4 9 16 25 36 49
> > $ var_a3: chr  "light" "light" "heavy" "heavy" ...
> >```
> >
> >Thank you
> >
>
> --
> Sent from my phone. Please excuse my brevity.



-- 
Best regards,
Luigi



More information about the R-help mailing list