similar to: vectorisation?

Displaying 20 results from an estimated 6000 matches similar to: "vectorisation?"

2010 Jul 28
2
finding the next highest number in an array
Hi I have a sorted array ( in ascending order) and I want to find the subscript of a number in the array which is the the next highest number to a given number. For example,if I have 67 as a given number and if I have a vector x=c(23,36,45,62,79,103,109), then how do I get the subscript 5 from x (to get 79 which is the next highest to 67) without using a for loop? Thx -- 'Raghu'
2010 Jul 28
3
how to code it??
Hi I have say a large vector of 3500 digits. Initially the digits are 0s and 1s. I need to check for a rule to change some of the 0s to -1s in this vector. But once I change a 0 to -1 then I need to start applying the rule to change the next 0 only after I see the next 1 in the vector. Say for example x = (0,0,0,0,0,0,0,1,0,0,1,1,0,0,1,0,0,0,1) I need to traverse from the 9th element to the last
2009 Jul 15
2
(newbie) sum for certain number of rows
I have following data in a data.csv file separated by space 0 0 1 0 0 1 0 1 0 0 0 0 0 0 0 0 1 0 0 1 1 0 1 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 1 0 1 1 0 1 0 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 etc... I wish to calculate the sum of each column for certain number of rows. For example if I want sum of the data after each 3 rows, it should display 1 0 1 1 1 1 1 1 1 1 1 1 0 0 1 1 2 3 2 3 3
2012 Jan 24
1
problems with rollapply {zoo}
Here is a relatively simple script (with comments as to the logic interspersed): # Some of these libraries are probably not needed here, but leaving them in place harms nothing: library(tseries) library(xts) library(quantmod) library(fGarch) library(fTrading) library(ggplot2) # Set the working directory, where the data file is located, and read the raw data
2012 Jul 08
3
Help in Optimization of a function
guRus! I have a function f = exp(x^2-y+(1/z)) Also, x can take values from 1 to 37, y from 2 to 20 and Z from -13 to 51. How can I find the maximum of f using any of the optimization functions please? Is there a way to store the possible values of x, y and Z in a single variable like in a List or in a multi-dimensional array? Thanks for your help Raghu [[alternative HTML version deleted]]
2010 Aug 06
3
How to apply apply?!
guRus I have say a dataframe, d and I wish to do the following: 1) For each row, I want to take one particular value of the row and multiply it by 2. How do I do it. Say the data frame is as below: OPEN HIGH LOW CLOSE 1931.2 1931.2 1931.2 1931.2 0 0 0 999.05 0 0 0 1052.5 0 0 0 987.8 0 0 0 925.6 0 0 0 866 0 0 0 1400.2 0 0 0 754.5 0 0 0 702.6 0 0 0 653.25 0 0 0 348 0 0 0 801 866.55 866.55
2012 Jul 14
2
writing data into files whose names are in a vector
GuRus How do I use the write function (or write.table or write.csv) to achieve the following please? age=c(32,37,39) names=c("john","peter","jake") I would like create in a directory 3 files each named as john.csv,peter.csv and jake.csv and each file have data from the age vector. That is jon.csv will contain 32, peter.csv will contain 37 and jake.csv will contain
2010 Jul 12
6
in continuation with the earlier R puzzle
When I just run a for loop it works. But if I am going to run a for loop every time for large vectors I might as well use C or any other language. The reason R is powerful is becasue it can handle large vectors without each element being manipulated? Please let me know where I am wrong. for(i in 1:length(news1o)){ + if(news1o[i]>s2o[i]) + s[i]<-1 + else + s[i]<--1 + } --
2012 Apr 22
2
difficulty in Formatting time series data
Dear R-Gurus I have a data frame (from CSV file) which has its first column called Date. The Date is in the format mm/dd/yyyy. I was trying to get the weekday for these dates and I tried using wday() and day.of.week() functions and both of them gave me precisely the wrong answers. I think the issue lies in the proper formatting of dates. The class of this column is a factor class and hence I
2008 Dec 16
8
sliding window over a large vector
Hi all, I have a very large binary vector, I wish to calculate the number of 1's over sliding windows. this is my very slow function slide<-function(seq,window){ n<-length(seq)-window tot<-c() tot[1]<-sum(seq[1:window]) for (i in 2:n) { tot[i]<- tot[i-1]-seq[i-1]+seq[i] } return(tot) } this works well for for reasonably sized vectors. Does
2012 Jul 24
3
Collapsing a vector/data-frame based on the previous values
Hello I have a data frame like this: dput(states) structure(list(Date = c("24/07/2012", "25/07/2012", "26/07/2012", "27/07/2012", "28/07/2012", "24/07/2012", "25/07/2012", "26/07/2012", "27/07/2012", "28/07/2012"), State = c(1L, 1L, 1L, 1L, 1L, -1L, -1L, -1L, 1L, -1L)), .Names = c("Date",
2009 Apr 29
3
selecting ith rows of a matrix
Hi all, If I have a huge matrix/ dataframe and I want to create a new matrix/ dataframe with every second (or third, or fourth etc.) row of the original matrix, how can I do it? Any help much appreciated. Thanks, Umesh [[alternative HTML version deleted]]
2010 Jul 12
2
a small puzzle?
I know the following may sound too basic but I thought the mailing list is for the benefit of all levels of people. I ran a simple if statement on two numeric vectors (news1o and s2o) which are of equal length. I have done an str on both of them for your kind perusal below. I am trying to compare the numbers in both and initiate a new vector s as 1 or 0 depending on if the elements in the arrays
2010 Nov 09
3
Row-wise recurive function call
Dear Group, I have a following dataset: > a A B C D 1 22 3 31 40 2 26 31 36 32 3 3 7 49 16 4 24 40 27 26 5 20 45 47 0 6 34 43 11 18 7 48 48 24 2 8 3 16 39 48 9 20 49 7 21 10 17 36 47 10 > dput(a) structure(list(A = c(22L, 26L, 3L, 24L, 20L, 34L, 48L, 3L, 20L, 17L), B = c(3L, 31L, 7L, 40L, 45L, 43L, 48L, 16L, 49L, 36L), C = c(31L, 36L, 49L, 27L, 47L, 11L, 24L,
2012 Apr 20
3
Matrix multiplication by multple constants
Dear R helpers Suppose x  <- c(1:3) y  <- matrix(1:12, ncol = 3, nrow = 4) > y      [,1] [,2] [,3] [1,]    1    5    9 [2,]    2    6   10 [3,]    3    7   11 [4,]    4    8   12 I wish to multiply 1st column of y by first element of x i.e. 1, 2nd column of y by 2nd element of x i.e. 2 an so on. Thus the resultant matrix should be like > z      [,1]   [,2]    [,3] [1,]    1   
2009 Jun 23
4
Very slow transfers to Samba on Ubuntu
I mounted a samba volume on XP. XP and Ubuntu are connected over 100Mbps ethernet (router). I am writing a 4GB file from XP to Ubuntu and the transfer is extremely slow : only around 1-1.5 MB/s. This is not a network or disk issue since at the same time this transfer is gonig on, I can scp the same file from XP to Ubuntu at 3-4 times faster (around 6MB/s). What could be wrong? Even for this
2012 Jun 19
1
Profit calculation
Dear guRus Say I have a price vector, P which is P = c(20,50,40,50) for four consecutive days. My initial equity is say $100 and I re-invest the profits made in each transaction so my equity curve increases. If I go Long on day 1, short and short on day 2, long and long on day 3 and finally short on day 4, how do I calculate the total profits using R? Basically I stay invested at all times. I
2009 Feb 17
2
Efficient matrix computations
Hi, I am looking for two ways to speed up my computations: 1. Is there a function that efficiently computes the 'sandwich product' of three matrices, say, ZPZ' 2. Is there a function that efficiently computes the determinant of a positive definite symmetric matrix? Thanks, S.A. [[alternative HTML version deleted]]
2010 Aug 06
2
How to read a file inside a function?
Hi I wish to read a file from my local directory from inside a function. I am passing the filename as the argument but this does not work. Say for example function(dat) { dat1=read.csv("D:\\dat.csv",header=TRUE) } If I call funtion(dat) I get the following error. 'Intuitively' i understand this is a mistake but how do I overcome this and how can I read a file name passed as an
2006 Jan 07
2
VB on Linux with Wine
We have 50 complex applications written in Microsoft Visual Basic 6.0 providing banking solutions. We are seriously thinking of porting our applications to Linux under WINE. Is it possible to do so? Nature of our VB applications: ------------------------------ 1. Extensively used all controls provided in VB 2. Total size of our applications is around 2 million lines 3. Applications are having