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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T07:40:18+00:00 2026-05-23T07:40:18+00:00

Define: > dats <- list( df1 = data.frame(a=sample(1:3), b = as.factor(rep(325.049072M,3))), + df2 =

  • 0

Define:

> dats <- list( df1 = data.frame(a=sample(1:3), b = as.factor(rep("325.049072M",3))),
+       df2 = data.frame(a=sample(1:3), b = as.factor(rep("325.049072M",3))))
> dats
$df1
  a           b
1 3 325.049072M
2 2 325.049072M
3 1 325.049072M

$df2
  a           b
1 2 325.049072M
2 1 325.049072M
3 3 325.049072M

I want to remove the M character from column b in each data frame.

In a simple framework:

> t<-c("325.049072M","325.049072M")
> t
[1] "325.049072M" "325.049072M"
> t <- substr(t, 1, nchar(t)-1)
> t
[1] "325.049072" "325.049072"

But in a nested one, how to proceed? Here is one sorry attempt:

> dats <- list( df1 = data.frame(a=sample(1:3), b = as.factor(rep("325.049072M",3))),
+       df2 = data.frame(a=sample(1:3), b = as.factor(rep("325.049072M",3))))
> dats
$df1
  a           b
1 3 325.049072M
2 1 325.049072M
3 2 325.049072M

$df2
  a           b
1 2 325.049072M
2 3 325.049072M
3 1 325.049072M

> for(i in seq(along=dats)) {
+   dats[[i]]["b"] <- 
+           substr(dats[[i]]["b"], 1, nchar(dats[[i]]["b"])-1)
+ }
> dats
$df1
  a         b
1 3 c(1, 1, 1
2 1 c(1, 1, 1
3 2 c(1, 1, 1

$df2
  a         b
1 2 c(1, 1, 1
2 3 c(1, 1, 1
3 1 c(1, 1, 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-05-23T07:40:19+00:00Added an answer on May 23, 2026 at 7:40 am

    You can do this with lapply (and some coercion):

    stripM <- function(x){
    x$b <- substr(as.character(x$b),1,nchar(as.character(x$b))-1)
    x
    }
    lapply(dats,FUN=stripM)
    

    If you need that variable as a factor, you can include a line in stripM that converts is back to a factor, something like x$b <- as.factor(x$b).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Define: df1 <-data.frame( id=c(rep(1,3),rep(2,3)), v1=as.character(c(a,b,b,rep(c,3))) ) s.t. > df1 id v1 1 1 a
Define a list dats with two dataframes, df1 and df2 dats <- list( df1
Define: df <- data.frame(name=c(México,Michoacán),dat=c(1,2)) s.t. > df name dat 1 México 1 2 Michoacán
(define (lcs lst1 lst2) (define (except-last-pair list) (if (pair? (cdr list)) (cons (car list)
I want to define something like this in php : $EL = \n<br />\n;
Define a function replicate which given a list of numbers returns a list with
Is #define LBitmap std::list < CBITMAP *> a good practice? Edit: Allright, what can
Define z<- as.character(c(1_xx xx xxx_xxxx_12_sep.xls,2_xx xx xxx_xxxx_15_aug.xls)) such that > z [1] 1_xx xx
#define STRLEN 65 /*Create linked list */ struct node { char str[STRLEN]; struct node
Define a list: nat2::[(Integer, Integer)] that contains all pairs of nonnegative integers ordered by

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.