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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T05:55:09+00:00 2026-06-03T05:55:09+00:00

I am trying to do PCA analysis using princomp function in R. The following

  • 0

I am trying to do PCA analysis using princomp function in R.

The following is the example code:

mydf <- data.frame (
    A = c("NA", rnorm(10, 4, 5)), 
    B = c("NA", rnorm(9, 4, 5), "NA"),
    C =  c("NA", "NA", rnorm(8, 4, 5), "NA")
)

out <- princomp(mydf, cor = TRUE, na.action=na.exclude)

Error in cov.wt(z) : 'x' must contain finite values only

I tried to remove the NA from the dataset, but it does not work.

ndnew <- mydf[complete.cases(mydf),]

                   A                  B                C
1                  NA                 NA               NA
2    1.67558617743171   1.28714736288378               NA
3   -1.03388645096478    9.8370942023751 10.9522215389562
4    7.10494481721949   14.7686678743866 4.06560213642725
5     13.966212462717   3.92061729913733 7.12875100279949
6   -1.91566982754146  0.842774330179978 5.26042516598668
7  0.0974919570675357    5.5264365812476 6.30783046905425
8    12.7384749395121   4.72439301946042  2.9318845479507
9    13.1859349108349 -0.546676530952666 9.98938028956806
10   4.97278207223239   6.95942086859593 5.15901566720956
11  -4.10115142119221                 NA               NA

Even if I can remove the NA‘s it might not be of help as every rows or column has at least one missing values. Is there any R method that can impute the data doing PCA analysis?


UPDATE: based on the answers:

> mydf <- data.frame (A = c(NA, rnorm(10, 4, 5)), B = c(NA, rnorm(9, 4, 5), NA),
+  C =  c(NA, NA, rnorm(8, 4, 5), NA))
> out <- princomp(mydf, cor = TRUE, na.action=na.exclude)
Error in cov.wt(z) : 'x' must contain finite values only

ndnew <- mydf[complete.cases(mydf),]
out <- princomp(ndnew, cor = TRUE, na.action=na.exclude)

This works but the defult na.action does not work.

Is there is any method that can impute the data, as in real data I have almost every column with missing value in them? The result of such NA omission will give me ~ 0 rows or columns.

  • 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-03T05:55:11+00:00Added an answer on June 3, 2026 at 5:55 am

    For na.action to have an effect, you need to explicitly supply a formula argument:

    princomp(formula = ~., data = mydf, cor = TRUE, na.action=na.exclude)
    
    # Call:
    # princomp(formula = ~., data = mydf, na.action = na.exclude, cor = TRUE)
    # 
    # Standard deviations:
    #    Comp.1    Comp.2    Comp.3 
    # 1.3748310 0.8887105 0.5657149 
    

    The formula is needed because it triggers dispatch of princomp.formula, the only princomp method that does anything useful with na.action.

    methods('princomp')
    [1] princomp.default* princomp.formula*
    
    names(formals(stats:::princomp.formula))
    [1] "formula"   "data"      "subset"    "na.action" "..."  
    
    names(formals(stats:::princomp.default))
    [1] "x"      "cor"    "scores" "covmat" "subset" "..."   
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to apply PCA on my data using princomp(x) , that has been
I am working in Ubuntu Opencv.I am trying to do PCA analysis of a
Trying to get parameters from a PUT request using HttpServlet#doPut: public void doPut(HttpServletRequest request,
Trying to get comfortable with jQuery and I have encountered some sample code that
Trying to write a windows speech recognition macro. Written using XML and scripting language
Trying to figure out why my vertex shader works on my cell phone (Casio
Trying to figure out how to read in multiple variables through a file. for
Trying to execute a Powershell cmdlet from a MVC 3 Controller using impersonation but
Trying to understand radix sort for my data structures class. My teacher showed us
Trying to understand how EDE works by using it to generate Makefiles for 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.