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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T05:31:17+00:00 2026-06-01T05:31:17+00:00

I want to do some statistic analysis in R on a column with the

  • 0

I want to do some statistic analysis in R on a column with the same name but different length originating from several data frames. I created a list:

my.list <- list(df1, df2, df3, df4)

Now, as some elements of the column of interest (say: my.col) contain the word “FAILED” instead of numbers, I replace it by ‘NA’:

for (i in 1:length(my.list)){
   for (j in 1:length(my.list[[i]]$my.col)){
      if (my.list[[i]]$my.col[j] %in% c("FAILED"))
         {my.list[[i]]$my.col[j] <- 'NA'};
    } 
}

I am pretty sure that this is not the best solution for the problem, but at least it works. Although I have to say that it causes warnings that in another column (not my.col) there are unvalid factor levels that have been replaced by ‘NA’. No idea why it actually considers other columns than my.col. Suggestions for improvement are highly appreciated.

Now, the remaining numbers contain decimal comma instead of point. Although I tried to eliminate this problems while importing the .csv-file with “dec=”,””, this does not work out for columns that contain anything else than numbers (e.g. “FAILED”). So I have to replace the comma by the point, and this is what doesn’t work for me. I tried:

for (i in 1:length(my.list)){
      as.numeric(gsub(",", ".", my.list[[i]]$my.col)) 
}

This doesn’t give any errors, but it also doesn’t change anything, although if I type in e.g.

as.numeric(gsub(",", ".", my.list[[4]]$my.col))

it does what I want to do for the 4th element of the list. From my point of view, both should be the same. What’s the problem with this?

Btw, I prefer not to delete the other columns from the data frames because I might need them in future for other analysis.

  • 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-01T05:31:18+00:00Added an answer on June 1, 2026 at 5:31 am

    You can do this efficiently using the plyr package.

    Note that in the example, I use the built in iris data.
    Instead of replacing “FAILED” with NA, I replaced values of “versicolor”.
    Instead of replacing a coma with a period, I replaced an s with a w.

    my.list <- list(iris, iris)
    
    library(plyr)
    
    my.list<-llply(.data=my.list,
                   function(x) { x$Species<-as.character(x$Species)
                                 x$Species[x$Species=="versicolor"]<-"NA"
                                 x$Species<-gsub(pattern="s",
                                                 replacement="w",
                                                 x=x$Species)
                                 x$Species<-as.factor(x$Species)
                                 return(x)
                   })
    

    The as.character was added as an example of a way to circumvent problems with adding a level to a factor. The as.factor insure the column is return as a factor with the new levels.

    This will also give you the flexibility to convert from list to data.frame. Simply replace llply with ldply.

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

Sidebar

Related Questions

I am trying to make one query, to get some statistic data from database.
Let's say I want some instance of String behave differently from other, normal instances
i am new in ssrs i want some sugeestiion from You can i use
For statistical reasons, I want an extensive analysis from a dataset. I already have
I am not a statistics guy but have to deal with quite some data.
im making some statistic codes for my website (im a php developper). I want
I have a table that contains some statistic data which is collected per hour.
I want some slightly 'dynamic' XML source files. I want some of the element
I want some particular urls like springer.com to automatically convert to springer.com.proxy1.mycollege.edu. The second
I want some of the items to be bold depending on a property of

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.