Displaying 20 results from an estimated 20000 matches similar to: "how to convert list into a vector"
2009 Oct 25
3
Importing data from text file with mixed format
Hi,
I'm having difficulty importing my textfile that looks something like this:
#begin text file
Timepoint 1
ObjectNumber Volume SurfaceArea
1 5.3 9.7
2 4.9 8.3
3 5.0 9.1
4 3.5 7.8
Timepoint 2
ObjectNumber Volume SurfaceArea
1 5.1
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 <-
2008 Mar 13
3
Splitting a set of vectors in a list
I have a set of character vectors of uneven length
that I have stored in a list. I can easily enough get
any column of them using lapply but what I want is to
be able to create a matrix of them. Other than some
kind of brute force looping approach I have drawn a
blank.
Would somebody please suggest something? Thanks
Example.
mylist <- list(aa=c("cat","peach" ),
2005 Feb 17
6
Converting a list to a matrix - I still don't think I have it right
Hi
We have touched on this before, but I don't think I quite got it right.
So I have a list, each element of which is a a vector of 2 numbers:
> l2
$cat000_a01
[1] 0.3429944 4.5138244
$cat000_a02
[1] 0.1929336 4.3064944
$cat000_a03
[1] -0.2607796 4.1551591
What I actually want to convert this into is a matrix with the names
(cat000_a01 etc) as row names, the first element of each of
2005 Mar 16
8
Summing up matrices in a list
Dear all,
I think that my question is very simple but I failed to solve it.
I have a list which elements are matrices like this:
>mylist
[[1]]
[,1] [,2] [,3]
[1,] 1 3 5
[2,] 2 4 6
[[2]]
[,1] [,2] [,3]
[1,] 7 9 11
[2,] 8 10 12
I'd like to create a matrix M<-mylist[[1]]+mylist[[2]]
[,1] [,2] [,3]
[1,] 8 12 16
[2,] 10 14 18
2010 Sep 04
4
Please explain "do.call" in this context, or critique to "stack this list faster"
I've been doing some consulting with students who seem to come to R
from SAS. They are usually pre-occupied with do loops and it is tough
to persuade them to trust R lists rather than keeping 100s of named
matrices floating around.
Often it happens that there is a list with lots of matrices or data
frames in it and we need to "stack those together". I thought it
would be a simple
2013 Feb 12
3
grabbing from elements of a list without a loop
Hello!
# I have a list with several data frames:
mylist<-list(data.frame(a=1:2,b=2:3),
data.frame(a=3:4,b=5:6),data.frame(a=7:8,b=9:10))
(mylist)
# I want to grab only one specific column from each list element
neededcolumns<-c(1,2,0) # number of the column I need from each element of
the list
# Below, I am doing it using a loop:
newlist<-NULL
for(i in 1:length(mylist) ) {
2011 May 25
3
Accessing elements of a list
I have a list that is made of lists of varying length. I wish to create a
new vector that contains the last element of each list. So far I have used
sapply to determine the length of each list, but I'm stymied at the part
where I index the list to make a new vector containing only the last item
of each list
mylist =
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,]
2012 Mar 15
1
Help with operation on list of matrices
I'll appreciate your help on this. I have values stored in a list as in
"mylist" below. I need to sum the values over all elements of the list
aggregated by the names of the matrices.
mylist <- list(matrix(c(0.2, 0.4), 1, 2, dimnames = list(NULL, c("1",
"2"))),
matrix(c(0.1, 0.5), 1, 2, dimnames = list(NULL, c("1",
2012 Jan 16
3
list: index of the element, that is TRUE
Dear People,
I have got the following example for a vector and the index of the TRUE
element:
Myvector <- c(FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,TRUE)
which(Myvector)
Now I would like to find out the same for a list:
Mylist <- list(FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,FALSE,TRUE)
...
Does anyone know how to do this?
Thank you very much in advance,
Marion
[[alternative HTML
2009 Jul 14
2
How to provide list as an argument for the data.frame()
Hi R -users,
i've a table as describe below. I'm reading the numeric value presented in this table to populate a list.
#table
#============
#X A B C
#x1 2 3 4
#x2 5 7 10
#x4 2 3 5
#============
rawData <- read.table("raw_data.txt",header=T, sep="\t")
myList=list()
counter=0
for (i in c(1:length(rawData$X)))
{
print (i)
2012 Jun 26
2
flatten lists
I am looking for a function to flatten a list to a list of only 1
level deep. Very similar to unlist, however I don't want to turn it
into a vector because then everything will be casted to character
vectors:
x <- list(name="Jeroen", age=27, married=FALSE,
home=list(country="Netherlands", city="Utrecht"))
unlist(x)
This function sort of does it:
flatlist
2007 Aug 07
1
Naming Lists
Hi
Im pretty new to R and I have run in to a problem. How do I name all the
levels in this list.
Lev1 <- c("A1","A2")
Lev2 <- c("B1","B2")
Lev3 <- c("C1","C2")
MyList <- lapply(Lev1,function(x){
lapply(Lev2,function(y){
lapply(Lev3,function(z){
paste(unlist(x),unlist(y),unlist(z))
})})})
I would like to name the different
2009 Apr 01
1
Vector of Vectors
I have a matrix of data. I need to scan the matrix and find every
sequence from maxima to maxima across a row. I can write a loop to do
this easily. Problem is, I can't figure out how to store the results.
Each result is a vector of widely varying lengths. Ideally I'd like a
vector of these, i.e. a vector of vectors, so I can quickly iterate
through them and compute correlation
2008 Jan 18
1
Assigning into each of a list of dataframes
What is the right way to assign a new variable into each a of list of
data frames? Here is my failed attempt:
mylist <- list(df1 = data.frame(A = runif(5), B = runif(5)),
df2 = data.frame(A = runif(5), B= runif(5)))
lapply(mylist, function(x){x$Y <- x$A * x$B})
$df1
[1] 0.25589928 0.03446026 0.94992362 0.21388326 0.08668821
$df2
[1] 0.08771839 0.05643553 0.09036894
2011 Sep 29
1
multiplying list with vector
hello everybody,
i have got a question about lists:
i have got the following commands:
mylist <- list("v1"=c(1,2,2,1),"v2"=c(2,2,2,1),"v3"=c(1,1,1,1))
myvector <- c(100,10000,1000000)
now i would like to multiply each element of the list with the corresponding
element of the vector, that is to say:
v1*100
v2*10000
v3*1000000
i only could think of lapply
2009 Nov 05
1
how to collapse list into a matrix with names
Dear R-Helpers,
I have the following code:
data =
read.csv("test.csv",header=T,na.strings="-",row.names=1)
myData=as.matrix(data)
##myData is a 102x19 matrix
myList = alply(myData, 2,function(x){matrix(x,ncol=6,byrow=T)})
##myList is a list containing 19 matrices with the following names
> names(myList)
[1] "*ES" "*ET" "*ER"
2012 Feb 06
2
how do I exort a list of numbers into csv file?
Hi all,
I have a list of vector of numbers - the reason I used list of vector was
that I each list have different numbers of numbers which I don't know
before run-time.
mylist[[1]] = c(1, 2, 3)
mylist[[2]] = c (3, 4, 5, 6)
...
...
etc.
Could you please tell me if there is a way to dump all these at once into
csv file such that each row correspond to a vector or a cell of the list as
shown
2011 Apr 05
1
Help in splitting a list
Dear R users,
Let's say I have a list with components being 'm' matrices (as exemplified
in the "mylist" object below). Now, I'd like to subset this list based on an
index vector, which will partition each matrix 'm' in 2 sub-matrices. My
questions are:
1. Is there an elegant way to have the results shown in mylist2 for an
arbitrary number of matrices in mylist?