Here are two alternatives to consider, depending on what you are actually expecting as your output.
The first option outputs a set of vectors, but I find that to be a little bit unnecessary and can quickly litter your workspace with lots of objects.
The second option, which I prefer, creates a convenient data.frame
with each row representing one of the items from your vector "x".
Sample Data
x <- vector()
x[1] <- "3,2,4,34,2,9"
x[2] <- "45,,67,,,"
x[3] <- ",,,,99,"
Option 1
Names <- paste0("A", seq_along(x))
for (i in seq_along(x)) {
assign(Names[i], {Z <- scan(text=x[i], sep=","); Z[is.na(Z)] <- 0; Z})
}
A1
# [1] 3 2 4 34 2 9
A2
# [1] 45 0 67 0 0 0
A3
# [1] 0 0 0 0 99 0
Option 2
Z <- read.csv(text = x, header = FALSE)
Z[is.na(Z)] <- 0
Z
# V1 V2 V3 V4 V5 V6
# 1 3 2 4 34 2 9
# 2 45 0 67 0 0 0
# 3 0 0 0 0 99 0
Extracting values from a data.frame
is as easy as specifying the desired rows and columns.
Z[1, 3]
# [1] 4
Z[2, 4]
# [1] 0
Z[3, c(1, 3, 5)]
# V1 V3 V5
# 3 0 0 99