Reputation: 1396
I have a character vector of the form (below). When you read this vector it is one long string such as, "tBodyAcc-XYZ\tGravityAcc-XYZ\tBodyAccJerk-XYZ\BodyGyro-XYZ..."
where whitespace is split by the escape char "\".
How can I use gsub to replace the white space pattern = " ", replacement = " ", so that each variable name is surrounding by quotes and is an element of the vector?
Ideally, I'd be able to say varnames[1] and get back "tBodyAacc-XYZ".
Thank you for your time on this matter.
varnames <- "tBodyAcc-XYZ
tGravityAcc-XYZ
tBodyAccJerk-XYZ
tBodyGyro-XYZ
tBodyGyroJerk-XYZ
tBodyAccMag
..."
Upvotes: 2
Views: 338
Reputation: 887951
You could try
scan(text=gsub('\\s+', ' ', varnames), sep='', what='')
Upvotes: 1