To elaborate on John’s answer, df[“A”] (or df[:A] in newer versions) is the way 
to get access to a single column of a DataFrame. This is like df$A in R.
'
Once you have the column, you can index into elements like df[“A"][1]. From 
there, you could do df[“A"][1][11:13].

At the risk of being too detailed, it might be worth noting that indexing into 
strings is risky business unless they will always be ASCII, since Julia indexes 
into strings by byte, rather than by character.

 — John

On Feb 9, 2014, at 6:59 AM, j verzani <[email protected]> wrote:

> You can do your own vectorization:  df["B"] = map(x -> x[(end-2):end], 
> df["A"])
> 
> On Saturday, February 8, 2014 10:03:11 PM UTC-5, Rick Donnelly wrote:
> Suppose I create a simple DataFrame with one column:
> 
>     df = DataFrame(A = ["1234567890abc", "0987654321def"])
> 
> I would like to create a new column that contains only the last three 
> characters of A, but cannot figure out how to access indices of A. If it were 
> a simple string (i.e., A = "1234567890abc") then it would be simple 
> (A[11:13]). But df["A", 11:13] returns an error, as does df[["A"]][11:13]. 
> What am I missing?
> 
> If I was going to do this in R the code would be:
> 
>     df$B <- substr(df$A, 11, 13)
> 
> Any help in what is probably obvious to everyone but me would be greatly 
> appreciated.
> 

Reply via email to