# Splitting Values in a Column and Only Taking the Second Value

**URL:** https://discourse.julialang.org/t/splitting-values-in-a-column-and-only-taking-the-second-value/67917
**Category:** New to Julia
**Tags:** question, dataframes
**Created:** [September 9, 2021, 8:26am UTC](https://discourse.julialang.org/t/splitting-values-in-a-column-and-only-taking-the-second-value/67917 "2021-09-09T08:26:24Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Billpete002](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/billpete002/32/35091_2.png) [@Billpete002](https://discourse.julialang.org/u/Billpete002)
#### Post date: [September 9, 2021, 8:26am UTC](https://discourse.julialang.org/t/splitting-values-in-a-column-and-only-taking-the-second-value/67917/1 "2021-09-09T08:26:24Z")

</div>

Hi All,

I am having a tough time figuring out how to split a column and only use the second value from the split in R I would have used gsub:

```julia
maindf$pcc = gsub(".*-","", maindf$pcc)

```

Which is just splitting something like 1P-XXX into “1P” and “XXX” and then taking only the “XXX” and replacing the column with that value.

With Julia I found Strings.jl:

```julia
maindf = @chain rawdf begin
 @transform(:pcc = split.(:pcc, "-"))
end

```

Which produces an element Vector{Vector{SubString{String}}} with [“1P”, “XXX”]  
what do I need to add to split and then only take the the “XXX” part of this?

---

<div class="post-metadata">

### Author: ![sijo](https://avatars.discourse-cdn.com/v4/letter/s/da6949/32.png) [@sijo](https://discourse.julialang.org/u/sijo)
#### Post date: [September 9, 2021, 8:44am UTC](https://discourse.julialang.org/t/splitting-values-in-a-column-and-only-taking-the-second-value/67917/2 "2021-09-09T08:44:56Z")

</div>

The difficulty is that you’re operating on a whole column with `split.(:pcc, "-")`. To get the second element of each value you can do `getindex.(split.(:pcc, "-"), 2)`. Conceptually you want to do `split.(:pcc, "-").[2]` but broadcasting the indexing operation like this with `.[]` is not supported.

It’s easier to operate row by row:

```julia
@transform(@byrow :pcc = split(:pcc, "-")[2])

```

or even simpler:

```julia
@rtransform(:pcc = split(:pcc, "-")[2])

```
