Skip to content

show structure of selected columns of dataframe

3 messages · Luigi Marongiu, Jeff Newmiller

#
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)
[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?

```
'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
#
Really?

str( df[ , grep(".*_a*.", names(df)) ] )
On September 15, 2021 7:53:17 AM PDT, Luigi Marongiu <marongiu.luigi at gmail.com> wrote:

  
    
#
Thanks
On Wed, Sep 15, 2021 at 5:12 PM Jeff Newmiller <jdnewmil at dcn.davis.ca.us> wrote: