Gnark
Gnark

Reputation: 4222

How escape or sanatize slash using regex in R?

I'm trying to read in a (tab separted) csv file in R. When I want to read the column including a /, I get an error.

doSomething <- function(dataset) {
     a <- dataset$data_transfer.Jingle/TCP.total_size_kb
     ...
     }

The error says, that this object cannot be found. I've tried escaping with backslash but it did not work.

If anybody has got some idea, I'd really appreciate it!

Upvotes: 3

Views: 1086

Answers (2)

Marek
Marek

Reputation: 50704

Two ways:

dataset[["data_transfer.Jingle/TCP.total_size_kb"]]

or

dataset$`data_transfer.Jingle/TCP.total_size_kb`

Upvotes: 1

Yorgos
Yorgos

Reputation: 30445

Give

head(dataset)

and watch the name it has been given. Perhaps it would be something like:

dataset$data_transfer.Jingle.TCP.total_size_kb

Upvotes: 2

Related Questions