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

  • Home
  • SEARCH
  • 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 9179049
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T17:42:00+00:00 2026-06-17T17:42:00+00:00

I want to replace missing values or character values in a data with the

  • 0

I want to replace missing values or character values in a data with the row mean. for example in the data below, the missing values are denoted with “U” and I want to replace all the “U” from p1 to p6 with the values in the “ave” column for each row. There are thousands of the rows to replace.

num p1 p2 p3 p4 p5 p6   ave

L1  0  10 1  U  0  -10   1.3

L2  10  1 10 10 U  10    7.1

L3  U  10 10  U 1  -10   3.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-17T17:42:01+00:00Added an answer on June 17, 2026 at 5:42 pm

    Here’s one approach:

    mydf <- read.table(
      header = TRUE, stringsAsFactors = FALSE, 
      text = "num p1 p2 p3 p4 p5 p6   ave
              L1  0  10 1  U  0  -10   1.3
              L2  10  1 10 10 U  10    7.1
              L3  U  10 10  U 1  -10   3.1")
    
    cbind(mydf[1], 
          t(apply(mydf[-1], 1, 
                  function(x) ifelse(x == "U", x["ave"], x))))
    #   num  p1 p2 p3  p4  p5  p6 ave
    # 1  L1   0 10  1 1.3   0 -10 1.3
    # 2  L2  10  1 10  10 7.1  10 7.1
    # 3  L3 3.1 10 10 3.1   1 -10 3.1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to replace all html codes to empty space. I think I should
I want to replace all occurrences of a comma in a few lines of
I want to replace all "%" with "%%" in my string. However, my string
So I'm dealing with a csv file that has missing values. What I want
I want to change the variable values in all links on the page. If
I want to find the means of all values in groups of columns. A
Array replace doesn't work properly or I'm missing something. I want to replace any
I want replace a(or each) element(number) instead another element(number) in a class while running
I want to replace some headers by images, so I would have nice font.For
i want to replace the bottom panel where we show Next,Back buttons with a

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.