similar to: Using lapply with two lists

Displaying 20 results from an estimated 2000 matches similar to: "Using lapply with two lists"

2009 Jul 24
1
Conditional sorting
Greetings! I am trying to figure out how to order a data frame by one variable conditioned on another. Here is an example of what I have: d <- data.frame(RUN = rep(1:3, each = 3), ID = 1:9, AUC = runif(9,1,100)) > d RUN ID AUC 1 1 70.2 1 2 86.5 1 3 20.1 2 4 74.3 2 5 53.6 2 6 67.6 3 7 99.9 3 8 47.3 3 9 41.3
2011 Mar 07
4
png inside loop
hello list! I'm sorry, I just stumbled over this strange behaviour (at least I am not able to explain the behaviour, therefore I assume it to be a strange behaviour): attach(water) # I know, this is not recommended names(water[3:10]) [1] "temp" "pH" "DO" "BOD" "COD" "no3" "no2" "po4" for (i in
2010 Mar 03
5
filtering signals per day
Hello R lovers, I have a vector of dates and signals. I want to filter the signals per day in a way that only the first signal of the day remains like this: Dates Signals Filtered Signal 2006-11-02 0 0 2006-11-02 1 1 2006-11-02 0 0 2006-11-02 1 0 2006-11-02 1
2010 Jan 29
7
Simple question on replace a matrix row
Hello, I have a matrix mat1 of dim [1,8] and mat2 of dim[30,8], I want to replace the first row of mat2 with mat1, this is what I do: mat2[1,]<-mat1 but it transforms mat2 in a list I don't understand, I want it to stay a matrix... ----- Anna Lippel -- View this message in context: http://n4.nabble.com/Simple-question-on-replace-a-matrix-row-tp1427857p1427857.html Sent from the R help
2010 Mar 26
5
smart way to turn a vector into a matrix
Hello guys, I am working on a matrix which looks like this one: > initialMatrix <- > rbind(cbind(rep("A",3),seq(1,3)),cbind(rep("B",4),seq(1,4)),cbind(rep("C",3),seq(1,3))) > initialMatrix [,1] [,2] [1,] "A" "1" [2,] "A" "2" [3,] "A" "3" [4,] "B" "1" [5,]
2010 Mar 25
4
Convert number to Date
Hello, I have a date value in excel: 1/4/2010 which in number format gives me 40182. When I read this with read.xls from R I get same 40182 so what I do is that I use the as.Date() function but here is what the as.Date() function returns me: > as.Date(40182) [1] "2080-01-06" Why don't I get the same thing as in excel? Thanks! ----- Anna Lippel -- View this message in context:
2010 Jan 29
3
Applying a function on each columns of a matrix
Hello everyone, I have the following matrix [,1] [,2] [,3] [,4] [1,] 0.002809706 0.0063856960 0.0063856960 0.011749681 [2,] 0.004893124 0.0023118418 -0.0005122951 -0.014646465 [3,] 0.003547897 0.0063355297 0.0030410542 0.011403953 [4,] 0.004838299 -0.0040383645 -0.0090406831 -0.011027569 [5,] 0.035648755 0.0334815590 0.0380977404
2009 Nov 16
5
Writing a data frame in an excel file
Hello, I am having trouble by using the write.table function to write a data frame of 4 columns and 7530 rows. I don?t know if I should just use a sep="\n" and change the .xls file into a .csv file. Thanks in advance ----- Anna Lippel new in R so be careful I should be asking a loooooooot of questions!:teeth: -- View this message in context:
2010 Feb 03
2
Delete missing value rows from a matrix
Hi everyone, I have a matrix with many Na's. Some rows contain some Na's and some others are entirely composed of Na's. I want to delete the rows that are entirely composed of Na's but not the other ones so I can't use a simple removeNA. Has any one an idea? ----- Anna Lippel -- View this message in context:
2010 Mar 11
2
Can't convert list to matrix properly
Hi guys, here is a list of names that I have: MyList: > myList<-list("A", "B","C","D") > myList [[1]] [1] "A" [[2]] [1] "B" [[3]] [1] "C" [[4]] [1] "D" I want to turn this list into a matrix of 1 row and 4 columns with those four components (A, B, C, D) so here is what I do: myDataFrame <-
2010 Feb 12
3
Code working but too slow, any idea for how to speed it up ?(no loop in it)
Hello my friends, here is a code I wrote with no loops on matrix that is taking too long (2 seconds and I call him 720 times --> 12 minutes): mat1 and mat2 are both matrix with 103 columns and 164 rows. sequence <- matrix(seq(1 : ncol(mat1))) returns <- apply(sequence, 1, function, mat1= mat1, mat2 = mat2, day = 1) function<- function(mat1, mat2, colNb, day){
2009 Nov 20
2
Problem at adding lines on a graphics with lines() function
Hello, I am trying to plot a graphic with many lines with the following command: plot(datas[1:n,1],datas[1:n,2],type="l",main="SP500 Prices and Moving Averages",xlab="Date",ylab="Prices",col="black") lines(datas[1:n,1],datas[1:n,3],type="l",col="green",lty="solid") But I just see the first curve. I have tried it on
2010 Jan 28
2
Error on using lag function
Hello everyone, I have a vector P and I want to replace each of its missing values by its next element, for example: P[i] = NA --> P[i] = P[i+1] To do this I am using the replace() and lag() functions like this: P <- replace(as.ts(P),is.na(as.ts(P)),as.ts(lag(P,1))) but here is the error that I get: Warning message: In NextMethod("[<-") : number of items to replace is not a
2010 Feb 02
1
Build a matrix from another matrix by specifying the indexes
Hello R specialists, I have a base vector called vBase with 102 elements. I have another vector vec1 which elements are only part of vBase but is shorter. I transform vec1 so I get a vector with the same size as vBase and with each common element on the same indexed row. If a value is missing in vec1 then I put a Na like this: vec1 vBase Amsterdam Amsterdam Na
2010 Feb 02
2
Retrieve distinct values within a whole data frame
Hello everyone, I am trying to retrieve the list of distinct values within a whole data frame. I tried to use unique() function but it retrieves the distinct values within each column or row, I want it for the entire data frame, any idea? ----- Anna Lippel -- View this message in context: http://n4.nabble.com/Retrieve-distinct-values-within-a-whole-data-frame-tp1460205p1460205.html Sent from
2010 Apr 19
2
Using split and then unsplit
Hello everyone, I use the split function splitting with the f function on a 3 columns and more than 100 000 rows data frame. Once it's split I have a list of data frames still with 3 columns and n rows. I manipulate those list elements and get a list of data frames still with 3 columns but less rows. So when I unsplit it, I get an error as I use the same factor function I used to split ( f in
2010 Mar 17
2
Troubles on retrieving rownames
Hi guys, I am using the blp() function from RBloomberg package which returns a matrix of prices with the columns corresponding to the security name and the columns to the date. When I have a look at the matrix I can see the rownames (dates) on the left of the prices but when I call the rownames() function it returns me a NULL value. It worked perfectly until I had to reinstall the RBloomberg
2010 Jan 26
3
Apply a function on an array with the parameter as an array
Hello R buddies, I want to apply a function on an array but for each element of the array I want to use a different parameter, So here is how I tried to enter the function: apply(as.matrix(X),2, function, parameter1 = arrayOfParameter) I put X as a matrix because it was initially an element of a list. It returns me an array with the same length as X but with values that I don't even
2009 Nov 18
1
Creating an excel file and manipulating it from R
Hello everybody, I?ve been looking for a function that would create an excel file in my working directory where I would write my dataframe but I only found the functions to write or read in an existing file that you gave me on my former post or on some websites. I can?t find either functions to manipulate those datas: for example, I would like some lines to be red or green according to their
2010 Feb 02
1
Finding the difference between two vectors
Hello everyone, I have two vectors having only one element different: vector1 vector2 vector1 TWC TWC TWC VFC TWX NA VIA/B VFC VFC