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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T07:02:17+00:00 2026-06-14T07:02:17+00:00

I am trying to do PCA on data frame with 5000 columns and 30

  • 0

I am trying to do PCA on data frame with 5000 columns and 30 rows

Sample <- read.table(file.choose(), header=F,sep="\t")
Sample.scaled <- data.frame(apply(Sample,2,scale))
pca.Sample <- prcomp(Sample.scaled,retx=TRUE)`

Got the error

Error in svd(x, nu = 0) : infinite or missing values in 'x'

sum(is.na(Sample))
[1] 0

sum(is.na(Sample.scaled))
[1] 90

Tried to ignore all na values by using the following

pca.Sample <- prcomp(na.omit(Sample.scaled),retx=TRUE)

Which gives the following error

Error in svd(x, nu = 0) : 0 extent dimensions

There were reports that na.action requires formula to be given and hence tried the below

pca.Sample <- prcomp(~.,center=TRUE,scale=TRUE,Sample, na.action=na.omit)

Now getting the following error

Error in prcomp.default(x, ...) :
  cannot rescale a constant/zero column to unit variance

Think that the problem might be because “One of my data columns is constant. The variance of a constant is 0, and scaling would then divide by 0, which is impossible.”

But not sure on how to tackle this. Any help much appreciated ….

  • 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-14T07:02:20+00:00Added an answer on June 14, 2026 at 7:02 am

    Judging by the fact that sum(is.na(Sample.scaled)) comes out as 90, when sum(is.na(Sample)) was 0, it looks like you’ve got three constant columns.

    Here’s a randomly generated (reproducible) example, which gives the same error messages:

    Sample <- matrix(rnorm(30 * 5000), 30)
    Sample[, c(128, 256, 512)] <- 1
    
    Sample <- data.frame(Sample)
    Sample.scaled <- data.frame(apply(Sample, 2, scale))
    
    > sum(is.na(Sample))
    [1] 0
    
    > sum(is.na(Sample.scaled))
    [1] 90
    
    # constant columns are "scaled" to NA.
    > pca.Sample <- prcomp(Sample.scaled,retx=TRUE)
    Error in svd(x, nu = 0) : infinite or missing values in 'x'
    
    # 3 entire columns are entirely NA, so na.omit omits every row
    > pca.Sample <- prcomp(na.omit(Sample.scaled),retx=TRUE)
    Error in svd(x, nu = 0) : 0 extent dimensions
    
    # can't scale the 3 constant columns
    > pca.Sample <- prcomp(~.,center=TRUE,scale=TRUE,Sample, na.action=na.omit)
    Error in prcomp.default(x, ...) : 
      cannot rescale a constant/zero column to unit variance
    

    You could try something like:

    Sample.scaled.2 <- data.frame(t(na.omit(t(Sample.scaled))))
    pca.Sample.2 <- prcomp(Sample.scaled.2, retx=TRUE)
    

    i.e. use na.omit on the transpose to get rid of the NA columns rather than rows.

    • 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
Trying to figure out how to read in multiple variables through a file. for
I'm trying to read through PCA and saw that the objective was to maximize
Trying to understand radix sort for my data structures class. My teacher showed us
Trying to create a table with a bigint column creates a standard integer column
Trying to read registry keys remotly (from a host on local intranet)... All the
I am trying to learn to simplify my code and merge multiple data.frames (>2)
I'm trying to select a subset of features from a data that contains 2000
I am trying to use Weka for feature selection using PCA algorithm. My original
I am getting confused trying to run PCA on a set of spatial grids

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.