I'm trying to sum over columns containing certain characters, and i don't know how to achieve it by using grep-.
I want to sum the following columns. they all have "Under 1.30" and "Under 5 years only" in the names:
"Under 1.30: - Married-couple family: - With related children of the householder under 18 years: - Under 5 years only"
"Under 1.30: - Other family: - Male householder, no wife present: - With related children of the householder under 18 years: - Under 5 years only"
"Under 1.30: - Other family: - Female householder, no husband present: - With related children of the householder under 18 years: - Under 5 years only"
I tried the following code, but it returns more columns in addition to the 3 shown above.
names(B17022[,grep("^Under 1.30.[Under 5 years only]", names(B17022))])
For instance, it returns too:
"Under 1.30: - Married-couple family:"