Displaying 20 results from an estimated 10000 matches similar to: "element wise conditional assignment in r"
2007 Sep 03
3
element wise opertation between a vector and a list
I want to try to get a result of element wise addition between a
vector and a list. It can be done with "for statement." In order to
reducing computing time, I have tried to avoid "for state." If anybody
give me an idea, I would apprecite it much.
for example, with a & b as below lines,
a<- list(c(1,3),c(1,2),c(2,3))
b<-c(10,20,30)
I would like to have a list (like
2008 Oct 21
4
Multi matrix row-wise mapply?
Hi group!
Suppose I have 2 matrices A and B of equal dimensions.
I want to apply a function f to all corresponding pairs of rows from A
and B in an efficient manner.
Basically, I want
mapply(f, data.frame(A), data.frame(B))
but for rows.
How do I do it?
Thanks,
Andrey
2010 Sep 13
3
Question: Form a new list with the index replicated equal to the number of elements in that index
Dear R-Helpers,
I have a list l1 like:
l1[[1]]
a b c
l1[[2]]
d
l1[[3]]
e f
I want an output res like:
res[[1]]
1 1 1
res[[2]]
2
res[[3]]
3 3
Essentially, I want to replicate each index equal to the number of elements
present in that index.
Below is what I do to accomplish this:
l1 <- list(c("a", "b", "c"), "d", c("e", "f"))
2010 Aug 24
1
Index list by other list (w/ logical elements)?
I have two lists of the same shape, like this:
x <- list()
x[[1]] <- c("one","two")
x[[2]] <- c("three","four","five")
y <- list()
y[[1]] <- c(TRUE,FALSE)
y[[2]] <- c(FALSE,TRUE,TRUE)
I would like to index x "by" y, that is, the result in this case
should be:
z
[[1]]
[1] "one"
[[2]]
[1] "four"
2007 Mar 19
1
Row wise solving an equation
Hello R-list,
How can I row wise solve a function for which the input variables are written in a matrix or a vector and have the calculated output added to the matrix or written in a vector?
To specify my case in particular I continue: I would like R to calculate for me a value for ‘t’ which is function of input parameters A and B, which are comprised in a matrix called ‘ddt’ and some other
2009 Nov 30
3
Assign palette (e.g. rainbow) to a series of points on 1 plot
I have 11 vectors representing insect survival probabilities in
response to different levels of toxins at 10 concentrations
lx100=c(1,1,1,.8,.5,.4,.2,0)
day100=c(0,1,2,3,4,5,6,7,8)
lx90=c(1,1,1,1,.9,.8,.6,.4,.2,.1,0)
day90=c(0,1,2,3,4,5,6,7,8,9,10)
#...and so on10% and a zero (control) series
lx0=c(1,1,1,1,1,1,.9,.9,.8,.8,.6,.5,.4,.3,.2,.1,.1,0)
2010 Jun 11
1
Managing list elements
Hello, I have two lists with the same number of elements
> tail(LHS)
[[1]]
[1] "antecedentes.factor_riesgo=17" "antecedentes.estado=1"
"antecedentes.medio=4" "tarjetas_flagrancia.adquiriente2="
[[2]]
[1] "antecedentes.riesgo=1" "antecedentes.estado=1"
"antecedentes.medio=4"
2011 May 26
4
Applying "toupper" to only portions of text strings
Colleagues
Assume that I have a vector containing some text strings, some of which contain a particular character. I could like to apply "toupper" to the text before the character. For example (in this case, "|" is the particular character):
ORIGINAL:
TEXT <- c("aaaa", "bbb|cc", "|ddd")
AFTER APPLICATION OF toupper:
TEXT <-
2005 Apr 15
4
function corresponding to map of perl
Is there a function in R that corresponds to the
function ``map'' of perl?
It could be called like:
vector.a <- map( vector.b, FUN, args.for.FUN )
It should execute for each element ele.b of vector.b:
FUN( vector.b, args.for.FUN)
It should return a vector (or data.frame) of the results
of the calls of FUN.
It nearly works using:
apply( data.frame( vector.b ), 1, FUN,
2010 Oct 28
2
Determining a basal correct count
Here's another interesting problem: if you recall I have a data frame (LCvars1) that consists of about 1500 cases (rows) of data from kids who took a test of listening comprehension. The columns are their scores (1 = correct, 0 = incorrect, . = missing) on 140 test items. The items are numbered sequentially and are ordered by increasing difficulty as you go from left to right across the
2010 Sep 08
2
subbing a string vector for another string vector
I have a data frame with two columns:
image pattern
1 http://$IMAGE_ID$ www.url.com/image.jpg
2 $IMAGE_ID$ http://www.blah.com/image.gif
...
I want to replace "$IMAGE_ID$" with the corresponding entry in the pattern
column such that the result would appear as follows:
url
http://www.url.com/image.jpg
2010 Oct 01
2
How to apply vector value function to a multidimensional array indexed by the remaining dimensions?
Hi,
I am looking for some generalization of colSums and rowSums for general
vector valued functions, and for arrays of more than 2 dimensions.
So as a concrete example, suppose I have a 3 dimensional array, given by x
= array(1:100,c(3,4,5)).
and I want to sum the 3rd index of x to obain a 3 by 4 matrix. Using rowSums
would return a vector of length 3 because it treats the last two indices as
2009 Aug 26
6
Managing output
Hi,
Is there a way to build up a vector, item by item. In perl, we can
"push" an item onto an array. How can we can do this in R?
I have a loop that generates values as it goes. I want to end up with a
vector of all the loop results.
In perl it woud be:
for(item in list){
result <- 2*item^2 (Or whatever formula, this is just a pseudo example)
Push(@result_list,
2010 Nov 17
3
translate vector of numbers to indicies of 0/1 matrix
Hello All,
Searched around, haven't found a decent solution.
I'd like to translate a vector of numbers to a matrix (or to a list of
vectors) such that the vector values would serve as indicies of the 1's
in an otherwise-zero-filled matrix (or list of vectors). For example:
> a = c(1,3,3,4)
# perform operation
[,1] [,2] [,3] [,4]
[1,] 1 0 0 0
[2,] 0 0 1
2010 Aug 30
2
Band-wise Conditional Sum - Actual problem
Dear R helpers,
Thanks a lot for your earlier guidance esp. Mr Davind Winsemius Sir. However, there seems to be mis-communication from my end corresponding to my requirement. As I had mentioned in my earlier mail, I am dealing with a very large database of borrowers and I had given a part of it in my earlier mail as given below. For a given rating say "A", I needed to have the bad-wise
2010 Mar 15
1
problem in reading trajectory file
Hi,
I'm trying to read some trajectory files (text files) which have the form:
# trial n
# t X Y
0 1 2
0.2 1 3
0.4 1.2 4
...
# trial n+1
# t X Y
0 1 2
0.2 1.3 3.3
0.4 1.5 5
...
...
where the symbol # means that the line is not a numeric value, but I still
need to read the number of the trial (n=1, 2, etc.).
I
2011 Feb 21
1
Mutiplying a data frame to a list
Hi R community,
I have a question I'm sure is very simple for most of you.
I have a list, with each element being a matrix and the names of the
elements are numbers (like 1,3,...). I can extract the matrices and the
names individually. Now, I want to multiply each of the names to the
individual list matrices (after converting to numbers of course).
I could use a for loop, but the very
2010 Jan 17
3
enty-wise closest element
Dear R-users,
i have a simple problem maybe, but i don't see the solution. i want to
find the entry-wise closest element of an vector compared with another.
ind1<-c(1,4,10)
ind2<-c(3,5,11)
for (i in length(ind2):1)
{
print(which.min(abs(ind1-ind2[i])))
}
for ind2[3] it should be ind1[3] 10, for ind2[2] it should be ind1[2] 4
and for ind2[1] it should be ind1[1] 1. but with the
2009 Feb 11
2
Loop on characters
Hi,
suppose I have three vectors like :
l1 = 1:4
l2 = 4:9
l3 = 16:67
now I want to construct a loop like :
for (i in 1:3)
{
count1[i] = length(li) # i.e. it will take l1, l2, l3 according to
value of i
}
Can anyone please tell me how to do that?
Regards,
--
View this message in context: http://www.nabble.com/Loop-on-characters-tp21949173p21949173.html
Sent from the R help
2010 Jun 13
4
Are any values in one list contained within a second list
Silly question, but, can I test to see if any value of list a is contained in
list b without doing a loop? A loop is easy enough, but wanted to see if
there was a cleaner way. By way of example:
List 1: a, b, c, d, e, f, g
List 2: z, y, x, w, v, u, b
Return true, since both lists contain b
List 1: a, b, c, d, e, f, g
List 2: z, y, x, w, v, u, t
Return false, since the lists have no mutual