Can separate_rows() separate by individual character?

tinyteeth

I'm looking to use separate_rows() to tidy data, but my data does not have a delimiter. Instead, I want to "separate" by each individual character. Because there is no delimiter in the data, I'm not sure what can be put in the sep= option.

My data is set up like:

    cog   func
COG0115    EH
COG0117    H
COG0119    E
COG0124    J
COG0126    G
COG0129    EG

I've tried:

df %>% separate_rows(., 'func', sep='[A-Z]') 

But I realize this is telling the function to consider each capital letter a "delimiter" and is definitely not what I want as it results in an empty column...

Instead I am looking for:

    cog   func
COG0115    E
COG0115    H
COG0117    H
COG0119    E
COG0124    J
COG0126    G
COG0129    E
COG0129    G
akrun

A regex lookaround can be used as sep.

library(dplyr)
library(tidyr)
df %>% 
   separate_rows(func, sep = '(?<=.)(?=.)')
#       cog func
#1 COG0115    E
#2 COG0115    H
#3 COG0117    H
#4 COG0119    E
#5 COG0124    J
#6 COG0126    G
#7 COG0129    E
#8 COG0129    G

data

df <- structure(list(cog = c("COG0115", "COG0117", "COG0119", "COG0124", 
"COG0126", "COG0129"), func = c("EH", "H", "E", "J", "G", "EG"
)), class = "data.frame", row.names = c(NA, -6L))

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Way to separate out individual events

tidyr use separate_rows over multiple columns

repeat character and separate by comma

Separate variable in field by character

How can I separate time from character

Python - parse, split and separate text into individual rows

converting list into individual separate list

How to apply separate_rows() to all columns, passing a `sep` parameter?

How to remove overlapping contours and separate each character as an individual contour for character extraction?

Separate rows into columns using the first split character

Can i separate a character by every other comma?

separate_rows generating quotes around the result

Separate line where can be more character in perl

separate every character in a word

Separate character column by Nth character?

How do I separate a row with delimited values into individual rows?

Cloud Firestore, separate individual database

how to avoid "No common size" error for separate_rows()-function

Using tidyr::separate_rows on multiple connected rows

tidyr separate_rows with user defined function? (r / tidyverse)

Multiply every new rows created by `separate_rows`

How can I combine pivot_longer() and separate_rows() to get long data?

Can tidyverse separate_rows() retain information before each delimiter?

`dplyr` results change when filtering and separate_rows

What is the correct way of applying separate_rows to a data.frame?

how can I separate character versus digital with separate function

Keep separator using Regex in separate_rows()

R data frame dplyr separate_rows function on specific condition

Send entire rows in individual separate emails to different email recipiants

TOP Ranking

  1. 1

    Failed to listen on localhost:8000 (reason: Cannot assign requested address)

  2. 2

    How to import an asset in swift using Bundle.main.path() in a react-native native module

  3. 3

    Loopback Error: connect ECONNREFUSED 127.0.0.1:3306 (MAMP)

  4. 4

    pump.io port in URL

  5. 5

    Spring Boot JPA PostgreSQL Web App - Internal Authentication Error

  6. 6

    BigQuery - concatenate ignoring NULL

  7. 7

    ngClass error (Can't bind ngClass since it isn't a known property of div) in Angular 11.0.3

  8. 8

    Do Idle Snowflake Connections Use Cloud Services Credits?

  9. 9

    maven-jaxb2-plugin cannot generate classes due to two declarations cause a collision in ObjectFactory class

  10. 10

    Compiler error CS0246 (type or namespace not found) on using Ninject in ASP.NET vNext

  11. 11

    Can't pre-populate phone number and message body in SMS link on iPhones when SMS app is not running in the background

  12. 12

    Generate random UUIDv4 with Elm

  13. 13

    Jquery different data trapped from direct mousedown event and simulation via $(this).trigger('mousedown');

  14. 14

    Is it possible to Redo commits removed by GitHub Desktop's Undo on a Mac?

  15. 15

    flutter: dropdown item programmatically unselect problem

  16. 16

    Change dd-mm-yyyy date format of dataframe date column to yyyy-mm-dd

  17. 17

    EXCEL: Find sum of values in one column with criteria from other column

  18. 18

    Pandas - check if dataframe has negative value in any column

  19. 19

    How to use merge windows unallocated space into Ubuntu using GParted?

  20. 20

    Make a B+ Tree concurrent thread safe

  21. 21

    ggplotly no applicable method for 'plotly_build' applied to an object of class "NULL" if statements

HotTag

Archive