Hello, is it possible to fill an array with no using of the recycling rule? My problem. I want to fill an array but my values have not always the same length. My aim. I want to fill the array only ONE TIME. All vacent places should be written with NA. Thank's a lot. Felix Example: -------- #Write 1 to 3 only one time. The last #5 place should be NA. dim(as.array(letters)) array(1:3, c(2,4) ) #na.strings = "NA"
How about A <- array(NA, c(2,4) ) x <- 1:3 A[seq_along(x)] <- x ? On Thu, 3 May 2007, Felix Wave wrote:> Hello, > is it possible to fill an array with no using of the recycling rule? > My problem. I want to fill an array but my values have not always > the same length. > My aim. I want to fill the array only ONE TIME. All vacent places > should be written with NA. > > > > Thank's a lot. > Felix > > > Example: > -------- > > #Write 1 to 3 only one time. The last > #5 place should be NA. > > dim(as.array(letters)) > array(1:3, c(2,4) ) > > #na.strings = "NA" > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >-- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595
First make your vectors to have the same length and then put them to the array. > x <- c(1,2) > x [1] 1 2 > length(x) <- 5 > x [1] 1 2 NA NA NA Petr Felix Wave napsal(a):> Hello, > is it possible to fill an array with no using of the recycling rule? > My problem. I want to fill an array but my values have not always > the same length. > My aim. I want to fill the array only ONE TIME. All vacent places > should be written with NA. > > > > Thank's a lot. > Felix > > > Example: > -------- > > #Write 1 to 3 only one time. The last > #5 place should be NA. > > dim(as.array(letters)) > array(1:3, c(2,4) ) > > #na.strings = "NA" > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code. >-- Petr Klasterecky Dept. of Probability and Statistics Charles University in Prague Czech Republic
Felix I'm not quite sure I understand your example, but try: a <- array(NA,c(2,2,3)) jj <- c(12,33,22) a[1:length(jj)] <- jj a which will fill only the first three elemens of array "a" HTH rksh On 3 May 2007, at 10:41, Felix Wave wrote:> Hello, > is it possible to fill an array with no using of the recycling rule? > My problem. I want to fill an array but my values have not always > the same length. > My aim. I want to fill the array only ONE TIME. All vacent places > should be written with NA. > > > > Thank's a lot. > Felix > > > Example: > -------- > > #Write 1 to 3 only one time. The last > #5 place should be NA. > > dim(as.array(letters)) > array(1:3, c(2,4) ) > > #na.strings = "NA" > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting- > guide.html > and provide commented, minimal, self-contained, reproducible code.-- Robin Hankin Uncertainty Analyst National Oceanography Centre, Southampton European Way, Southampton SO14 3ZH, UK tel 023-8059-7743