Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 206235

Renaming a column using name that includes a newline character/carriage return

$
0
0

I have imported survey response data and the variables need renamed as their far too long and unwieldly for analysing. As there's 140 variables i was using the rename function in the plyr package, which works for all of them except for one.

SPPS_Responses <- rename(SPPS_Responses, c("Q7.1. Central Policy\r\n\r\nActive Ageing & Disability Policy\r\n\r\nGender & LGBT Policy\r\n\r\nPfG Co-ordination\r\n\r\nPoverty, Child Poverty Policy/Anti-Poverty Policy\r\n\r\nProfessional Services Unit (Analytical Services Unit/Economics Branch)\r\n\r\nStrategic Policy & Planning, and Equality\r\n\r\n "="Q1: Group"))

When i run the above code i get the following error:

The following `from` values were not present in `x`: Q7.1. Central Policy

Active Ageing & Disability Policy

Gender & LGBT Policy

PfG Co-ordination

Poverty, Child Poverty Policy/Anti-Poverty Policy

Professional Services Unit (Analytical Services Unit/Economics Branch)

Strategic Policy & Planning, and Equality


>names(SPPS_Responses)

So it's telling me it can't find the variable, but i copied the name from the names() function and other variables have newline characters and were still renamed grand. The only difference between the problem variable and the others with new line characters is that it has a space on the end after the last newline character. The names() function showed it was called:

 [20] "Q7.1. Central Policy\r\n\r\nActive Ageing & Disability Policy\r\n\r\nGender & LGBT Policy\r\n\r\nPfG Co-ordination\r\n\r\nPoverty, Child Poverty Policy/Anti-Poverty Policy\r\n\r\nProfessional Services Unit (Analytical Services Unit/Economics Branch)\r\n\r\nStrategic Policy & Planning, and Equality\r\n\r\n "
 [21] "Q7.2. Financial Management\r\n\r\nBusiness Partners\r\n\r\nDepartmental Resource Accounts & Financial Systems\r\n\r\nFinance Change\r\n\r\nFinance Review\r\n\r\nFinancial Planning\r\n\r\nInternal Client Services\r\n\r\nWH & SP Accounts and Treasury Management\r\n\r\n\r\n"

What's going wrong that i can't see? The only other option i can think is to rename this particular column using position, but i'd like to know if there's a better option incase the column positions move the next time the data is exported from the survey tool.


Viewing all articles
Browse latest Browse all 206235

Trending Articles