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 9199675
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T22:35:19+00:00 2026-06-17T22:35:19+00:00

I am writing a utility function to do some data format conversion, and I

  • 0

I am writing a utility function to do some data format conversion, and I am having trouble stating it correctly, so that it applies to the data I want it to apply to, and returns a result of the right shape.

I have a test data set called HiRawTiny, the str demonstrated below. The data in V1 is char. I have a test function called GetRank, whose job is to take all chars to the right of a “:” and coerce them to numeric. This is also demonstrated below. The list of list syntax I used in the fn to get at the output of strsplit is a bit opaque to me, and I frankly I arrived at it by trial and error, but it appears to work ok when passed single values. But when I pass it a vector (a data frame column), it doesn’t give me a vector result that’s the same length as the vector I passed it, but only a single value.

What should I do to sort this out? I am new to R (though I used to use S many decades ago), and suspect I’ve got into a syntax muddle. Is my function syntax wrong given what I am trying to do? Should I be looking at using “apply” or one of its friends, to do this? Or should the fn be able to handle vector in/vector out natively?

str(HiRawTiny)

>'data.frame':  10 obs. of  7 variables:  
>$ V1: chr  "RANK:1" "RANK:2" "RANK:3" "RANK:4" ...  
$ V2: chr 
> "SOURCEID:CWC02001632398F4C" "SOURCEID:CWC020000F0D57DD6"
> "SOURCEID:CWC0200214C29872E" "SOURCEID:CWC0200163206B9F2" ...  
$ V3:
> chr  "TIME:01:04:2012-22:23:58" "TIME:01:04:2012-12:07:55"
> "TIME:01:04:2012-12:39:51" "TIME:02:04:2012-07:18:25" ...  
$ V4: chr 
> "SCORE:3142" "SCORE:3040" "SCORE:2911" "SCORE:2882" ...  
$ V5: chr 
> "TIEBREAK:4923864" "TIEBREAK:5787094" "TIEBREAK:766764"
> "TIEBREAK:1872936" ...  
$ V6: chr  "" "" "" "" ...  
$ V7: chr  "" ""
> "" "" ...

 GetRank function(x) {as.numeric(strsplit(x, split=":")[[1]][2]) }

GetRank(HiRawTiny[1,1]) [1] 1
GetRank(HiRawTiny[2,1]) [1] 2
GetRank(HiRawTiny[,1]) [1] 1

#"What I want is a vector of GetRank being applied to all of column 1
  • 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-06-17T22:35:20+00:00Added an answer on June 17, 2026 at 10:35 pm

    strsplit returs a list. Each element of the list contains the divided string. You can change the list into a matrix with do.call and rbind and then select the second column,

    GetRank <- function(x) {as.numeric(do.call(rbind, strsplit(x, split=":"))[, 2]) }
    
    GetRank(HiRawTiny$V1)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing an utility function that gets a integer from the database and returns
I'm writing a win32 utility function for our product that needs to call an
I'm writing a utility program with C# in WPF that allows users to create
I am writing a utility that would allow me to monitor the health of
I'm writing a little utility to load Entity Data Models from an assembly and
I am writing a small wxPython utility. I would like to use some event
I am writing a simple DOS utility that uses the findstr utility to search
I'm writing some code that uses dynamic shared libraries as plugins. My command line
I am writing a little utility function in Python which returns a boolean, indicating
First time writing Python code. Need some help in graphing this function. It is

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.