R error: infinite or missing values in 'x' when running svd(subs_mat)

You asked us the following:

#Download the subscriptions dataset. Select NbrNewspapers, TotalDiscount, TotalPrice, and TotalCredit and perform an svd on the
#first half of the dataset. Then, use your newly computed v and d to calculate u on the second half of the data.

# Read in the subscriptions data
URL_subs <-

subs <- read.table(URL_subs,
header=TRUE, sep=";")

subs <- subs[,c("NbrNewspapers", "TotalDiscount","TotalPrice","TotalCredit")]

This is my question:

How do you perform an svd on subs?

I did this:

subs_mat <- as.matrix(subs)

s <- svd(subs_mat)

Then there is this error message:

Error in svd(subs_mat) : infinite or missing values in 'x'

Answers and follow-up questions

Answer or follow-up question 1

Dear student,

The error message is self- explanatory: there are missing values in x.
That means that you first need to impute missing values.

Michel Ballings

Answer or follow-up question 2

This is my question:

How to perform an svd on only the first part of the dataset?

I imputed the missing values by using simple random imputation (I found the R code at

When you say perform an svd on only the first part of the dataset, I assume that you mean rows 1-113 of 227 rows.

I have tried s <- svd(subs_mat, nv=min(1,113)) to compute the svd on only rows 1-113, but it does not seem to work when I run "s" by itself.
The $u still shows 227 rows worth of information instead of the first 1-113 alone.

Answer or follow-up question 3

Missing value imputation is explained in Section ' Missingvalues'.
Subsetting data objects is explained in Section ' Subsetting'.

Michel Ballings

Sign in to be able to add an answer or mark this question as resolved.