jessiemcintyre
jessiemcintyre

Reputation: 89

In R, how do I separate a column based on position in that column?

In R, I have a data frame where I have several columns where I am simply looking to separate it, and make those separations into new columns.

I have tried multuple strings and such but can't seem to figure it out

Ex: 
Lat 
4440046
Deg min sec
44  40   046

Upvotes: 1

Views: 281

Answers (1)

tmfmnk
tmfmnk

Reputation: 39858

With tidyr, you can do:

separate(df, latt, into = c("deg", "min", "sec"), sep = c(2, 4))

  deg min sec
1  44  40 046

Sample data:

df <- data.frame(latt = c("4440046"),
                 stringsAsFactors = FALSE)

Upvotes: 1

Related Questions