search for: vecotrization

Displaying 19 results from an estimated 19 matches for "vecotrization".

Did you mean: vecorization
2008 Nov 25
2
creating a new vecotr in a for loop
I have consulted the intro and nabble but have not found an answer to what should be a simple question, here goes: I am doing a crosscheck of a data frame and pulling out a single value based on an inputted value ie based on x i will select y, or if x =2 then my code returns 7. x y 1 4 2 7 3 10 4 2 My code currently iterates through for as many times as the length of the x
2016 Apr 07
4
simple question on data frames assignment
Hi I'm not sure how to ask this, but its a very easy question to answer for an R person. What is an easy way to check for a column value and then assigne a new column a value based on that old column value? For example, Im doing colordata <- data.frame(id = c(1,2,3,4,5), color = c("blue", "red", "green", "blue", "orange")) for (i in
2016 Apr 07
0
simple question on data frames assignment
ifelse is vectorised, so just use that without the loop. colordata$response <- ifelse(colordata$color == 'blue', 1, 0) David On 7 April 2016 at 12:41, Michael Artz <michaeleartz at gmail.com> wrote: > Hi I'm not sure how to ask this, but its a very easy question to answer for > an R person. > > What is an easy way to check for a column value and then assigne a
2014 Nov 14
3
Cómo aplicar weights a las observaciones en un GLM binomial
Gracias por la ayuda Jose Luis. pero o no te he entendido bien o mi duda es tan sencilla que no me he explicado. SI yo tampoco he entendido mal tu explicación, mi problema es cómo obtengo ese "tus.pesos" para introducir, por ejemplo, en la función: library(survey) # objeto del diseño muestral ddatos <- svydesign(id=~1, weights =~ tus.pesos, data = tus.datos) # en caso de una reg
2016 Apr 07
2
simple question on data frames assignment
Hello, Or even simpler, without ifelse, colordata$response <- colordata$color == 'blue' + 0 Hope this helps, Rui Barradas ? Citando David Barron <dnbarron at gmail.com>: > ifelse is vectorised, so just use that without the loop. > > colordata$response <- ifelse(colordata$color == 'blue', 1, 0) > > David > > On 7 April 2016 at 12:41, Michael
2010 Mar 15
1
rbind, data.frame, classes
Hi, This has bugged me for a bit. First question is how to keep classes with rbind, and second question is how to properly return vecotrs instead of lists after turning an rbind of lists into a data.frame list1=list(a=2, b=as.Date("20090102", format="%Y%m%d")) list2=list(a=2, b=as.Date("20090102", format="%Y%m%d")) rbind(list1, list2) #this loses the
2009 Jan 14
2
Vectorization of three embedded loops
...ntel Core 2 Duo, Memory 2 GB 667 MHZ DDR2 SDRAM). I used for the heart of the script three embedded loops. This makes it especially for huge datasets very slow. For a datamatrix of 1853*1853 and the selection of 556 samples needed computation time of more than 24 hours. I did some research on vecotrization, but I could not figure out how to do it better/faster. Which ways are there to replace the time consuming loops? Here are some information: # val.n<-24; # start.b<-matrix(nrow=1812, ncol=20); # val is a vector of the rownames of 22 in an earlier step chosen extrem samples; # euc<-...
2016 Apr 07
4
simple question on data frames assignment
Thaks so much! And how would you incorporate lapply() here? On Thu, Apr 7, 2016 at 6:52 AM, David Barron <dnbarron at gmail.com> wrote: > ifelse is vectorised, so just use that without the loop. > > colordata$response <- ifelse(colordata$color == 'blue', 1, 0) > > David > > On 7 April 2016 at 12:41, Michael Artz <michaeleartz at gmail.com> wrote: >
2016 Apr 08
0
simple question on data frames assignment
Fyi, This statement returned the following error 'Error in "Yes" + 0 : non-numeric argument to binary operator' On Thu, Apr 7, 2016 at 8:43 AM, <ruipbarradas at sapo.pt> wrote: > Hello, > > Or even simpler, without ifelse, > > colordata$response <- colordata$color == 'blue' + 0 > > Hope this helps, > > Rui Barradas > > >
2016 Apr 07
2
simple question on data frames assignment
== is also vectorised, and you're better off with TRUE and FALSE rather than 1 and 0, so I'd recommend: colordata$response <- colordata$color == 'blue' Hadley On Thu, Apr 7, 2016 at 6:52 AM, David Barron <dnbarron at gmail.com> wrote: > ifelse is vectorised, so just use that without the loop. > > colordata$response <- ifelse(colordata$color ==
2016 Apr 07
2
simple question on data frames assignment
If you are not using an anonymous function and say you had written the function out The below gives me the error > 'f(colordata2$color1)' is not a function, character or symbol' But then how is the anonymous function working? f <- function(col){ ifelse(col == 'blue', 1, 0) } responses <- lapply(colordata2[ -1 ], f(colordata2$color1) )
2016 Apr 07
0
simple question on data frames assignment
Lapply is not a vectorized function. It is compact to read, but it would not be worth using for this calculation. However, if your data frame had multiple color columns in your data frame that you wanted to make responses for then you might want to use lapply as a more compact version of a for loop to repeat this operation. colordata2 <- data.frame(id = c(1,2,3,4,5), color1 =
2003 Jul 01
1
Creating a loop that works....
Hi there, First off, thanks to everyone who has helped me so far. Sorry to keep pestering you all. I'm including my code here, and I will comment down it where it is that I am having problems figuring out how to write this damn thing. > temper <- scan("temp2.dat", na.strings = ".", list(Day=0, Temp=0)) Read 366 records > > Day <- temper$Day ;
2016 Apr 07
0
simple question on data frames assignment
lapply(colordata2[ -1 ], f ) When you put the parentheses on, you are calling the function yourself before lapply gets a chance. The error pops up because you are giving a vector of numbers (the answer f gave you) to the second argument of lapply instead of a function. -- Sent from my phone. Please excuse my brevity. On April 7, 2016 7:31:18 AM PDT, Michael Artz <michaeleartz at
2016 Apr 08
0
simple question on data frames assignment
Why am I better off with true and false? On Thu, Apr 7, 2016 at 8:41 AM, Hadley Wickham <h.wickham at gmail.com> wrote: > == is also vectorised, and you're better off with TRUE and FALSE > rather than 1 and 0, so I'd recommend: > > colordata$response <- colordata$color == 'blue' > > Hadley > > On Thu, Apr 7, 2016 at 6:52 AM, David Barron
2010 Nov 15
1
Aggregate on identical link attributes
Hello R community, I need to do some aggregation based on the test data below. The below code works ok, but when its applied to my real data which includes over 9,000 records the process runs for over an hour. I know there is a more efficient way of doing this. I want to Sum the below data's volumes where FNODE and TNODE match, i.e. FNODE=1 and TNODE =20 -> Volume=100 ,
2013 Apr 29
3
all.vars for nested expressions
Dear R fellows, Assume I define a <- expression(fn+tp) sen <- expression(tp/a) Now I'd like to know, which variables are necessary for calculating sen all.vars(sen) This results in a vector c(tp,a). But I'd like all.vars to evaluate the sen-object down to the ground level, which would result in a vector c(tp,fn) (because a was defined as fn+tp). In other words, I'd like
2008 Jul 27
4
product of successive rows
Hi everyone, I want to perform an operation on a matrx that outputs the product of successive pairs of rows. For example: calculating the product between rows 1 & 2; 3 & 4; 5 & 6...etc. Does anyone know of any readily available functions that can do this? Thanks, rcoder -- View this message in context: http://www.nabble.com/product-of-successive-rows-tp18681259p18681259.html
2016 Apr 08
0
simple question on data frames assignment
Hi The question does not make much sense so as your code. Maybe you shall spend some time with R tutorials. 1. lapply or sapply is basically hidden cycle 2. function shall return something, yours does not So if you want some binary outcome from a vector you can use e.g. f <- function(vector, token) { response <- vector==token response } So with your colordata >