Hi I have the below dataframe. Since the column contains NA's the datatype of the column is character
. Now, I need to get the column name and index which only contains String value.
In the example below, I want to get the column name and column index of Zo-A and Zo-B:
ZONE-1 Zo-A Zone-3 Zo-B
58 On 75 NA
60 NA NA High
NA Off 68 Low
70 On NA NA
So far I tried to first convert all of them to numeric, which created NA's for Zo-A and Zo-B column. And if I use the below code for column index, I'm getting NA's as a result
a <- which(colnames(df)=="Zo-A" )
integer(0)
match_col <- match(c("Zo-A","Zo-B")names(df))
NA NA
I need to perform below operations:
- I need to first get the
column names
which consists ofString
values - I need the
column index
for the same
To obtain this we can use the code below: