Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 209727

Find first occurrence of a character in column of a data frame in R

$
0
0

Struggling with string handling in R...

I've got a column of strings in an R data frame. Each one contains the "=" character once and only once. I'd like to know the position of the "=" character in each element of the column, as a step to splitting the column into two separate columns (one for the bit before the "=" and one for the bit after the "="). Can anyone help please? I'm sure it's simple but I'm struggling to find the answer.

For example, if I have:

x <- data.frame(string = c("aa=1", "aa=2", "aa=3", "b=1", "b=2", "abc=5"))

I'd like a bit of code to return

(3, 3, 3, 2, 2, 4)

Thank you.


Viewing all articles
Browse latest Browse all 209727

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>