Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6125277
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T16:13:45+00:00 2026-05-23T16:13:45+00:00

I’m trying to, as the title says, change elements from my dataframe from one

  • 0

I’m trying to, as the title says, change elements from my dataframe from one character to another. The dataframe is as follows:

g1=c("CC","DD","GG")
g2=c("AA","BB","EE")
g3=c("HH","II","JJ")

df=data.frame(g1,g2,g3)

I wish to convert the elements from letterletter format to letter/letter format (e.g. CC to C/C or AA to A/A)

I know using “strsplit” would work on a list.
I also know that I would need to somehow incorporate: collapse=”/”

How would I be able to apply the strsplit function to the entire dataframe?

I was thinking something along the lines of:

split=function(x)
{
  unlist(paste(strsplit(x,""),collapse="/"))
}

j=as.data.frame(apply(df,1,split))

but it doesn’t give the desired results.

Update—————-
Apparently, the following script works:

split=function(x)
{
  paste(unlist(strsplit(x,"")),collapse="/")
}

p=apply(df,c(1,2),split)

If there is a more efficient or convenient way, please feel free to share.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T16:13:46+00:00Added an answer on May 23, 2026 at 4:13 pm

    I can think of two ways to approach this. One is using strsplit like you did. You were only missing the portion where you loop over each element in the list returned from strsplit:

    Split <- function(x) {
      #unlist(lapply(strsplit(x, ""), paste, collapse="/"))
      sapply(strsplit(x, ""), paste, collapse="/")
    }
    as.data.frame(lapply(df, Split))
    

    Another approach would be to use gsub and the \\B symbol, which matches the empty string that isn’t at the beginning or end of a “word”.

    as.data.frame(lapply(df, gsub, pattern="\\B", replacement="/"))
    

    What constitutes a “word” depends on locale and implementation, so here’s another solution using gsub and back-references.

    as.data.frame(lapply(df, gsub, pattern="(.)(.)", replacement="\\1/\\2"))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I want to construct a data frame in an Rcpp function, but when I
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I am trying to render a haml file in a javascript response like so:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.