[R] show structure of selected columns of dataframe

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


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

-- 
Best regards,
Luigi



More information about the R-help mailing list