similar to: extract all data frames from a list & remove NAs

Displaying 20 results from an estimated 20000 matches similar to: "extract all data frames from a list & remove NAs"

2007 Nov 15
2
how to extract the elements of a list of vectors in a fixed position?
Hi, How is it possible to extract athe elements of a list of vectors in a fixed position? suppose that I have a list of 2-element vectors, how can I extract the 2nd element of all vectors in the list? Can it be done with indexing and not by element name? Thanks carol So in this example, I want to extract 2 and 4 v = list (c(1,2), c(3, 4)) > v [[1]] [1] 1 2 [[2]] [1] 3 4
2012 Feb 08
2
remove NAs from list collectively
Hi, I am importing dataframe from an Excel file (xlsx package). The columns contain acutally measurements for single species and the column-length is of variable. As it is imported as a dataframe the difference to the "longest" column is filled with NA. To explain it with an example, my dataframe looks like: A <- seq(1:10) B <- c(seq(1:5),rep(NA,5)) C <- c(seq(1:7),rep(NA,3))
2010 Aug 24
2
Extract rows from a list object
Dear list members, I need to create a table from a huge list object, this list consists of matrices of the same size (but with different content). The resulting n tables should contain the same rows from all matrices. For example: n <- 23 x <- array(1:20, dim=c(n,6)) huge.list <- list() for (i in 1:1000) { huge.list[[i]] <- x } # One of 1000 matrices huge.list[[1]][1:4, 1:6]
2007 Jul 23
3
extraction of vector elements to new list
Dear R-community, I have got a list of vectors and would like to extract the first two elements of each vector to a new list. My list is of the style: my.list = list(c("a", "b", "c"), c("d", "e"), c("f", "g", "h", "i"), ...) #I want: new.list = list(c("a", "b"), c("d",
2007 Jan 24
4
Replace missing values in lapply
I have some matrices stored as elements in a list that I am working with. On example is provided below as TP[[18]] > TP[[18]] level2 level1 1 2 3 4 1 79 0 0 0 2 0 0 0 0 3 0 0 0 0 4 0 0 0 0 Now, using prop.table on this gives > prop.table(TP[[18]],1) level2 level1 1 2 3 4 1 1 0 0 0 2 3
2005 Jan 14
5
Replacing NAs in a data frame using is.na() fails if there are no NAs
Hi This is a difference between the way matrices and data frames work I guess. I want to replace the NA values in a data frame by 0, and the code works as long as the data frame in question actually includes an NA value. If it doesn't, there is an error: df <- data.frame(c1=c(1,1,1),c2=c(2,2,NA)) df[is.na(df)] <- 0 df df <- data.frame(c1=c(1,1,1),c2=c(2,2,2)) df[is.na(df)] <-
2005 Feb 17
3
A vector or array of data frames
Hi A simple question again, but I can't find it by google-ing R-help. Quite simply, I want to read in the contents of a number of files, using read.table, and assign the results to elements of a vector/array/list/whatever. I want it so that, if my vector/array/whatever is "pos", that pos[1] will give me the first data frame, pos[2] will give me the second etc... Kind of basic
2008 Sep 17
5
Loop on vector name
[My previous message rejected, therefore I am sending same one with some modification] I have 3 vectors with object name : dat1, dat2, dat3 Now I want to create a loop, like : for (i in 1:3) { cat(sd(dati)) } How I can do this in R? Regards,
2005 Mar 18
4
passing arguments to FUN in lapply
Suppose I have a nx2 matrix of data, X, the following code generate density estimation for each column and plot them denlist <- apply(X, 2, density) par(mfrow=c(1,2)) lapply(denlist, plot) Does anyone know how to change the main title of each density plot to "var 1", "var 2" by passing optional argument "main"? I've tried lapply(denlist, plot,
2005 Jun 13
3
extracting components of a list
Hi how do I extract those components of a list that satisfy a certain requirement? If jj <- list(list(a=1,b=4:7),list(a=5,b=3:6),list(a=10,b=4:5)) I want just the components of jj that have b[1] ==4 which in this case would be the first and third of jj, viz list (jj[[1]],jj[[3]]). How to do this efficiently? My only idea was to loop through jj, and set unwanted components to NULL,
2007 Jun 08
4
logical 'or' on list of vectors
Suppose I have a list of logicals, such as returned by lapply: Theoph$Dose[1] <- NA Theoph$Time[2] <- NA Theoph$conc[3] <- NA lapply(Theoph,is.na) Is there a direct way to execute logical "or" across all vectors? The following gives the desired result, but seems unnecessarily complex. as.logical(apply(do.call("rbind",lapply(Theoph,is.na)),2,"sum"))
2013 Jun 06
2
generating a bar chart with two axis for co-linear variable
Hello Dimitris, I was goggling for some help on Sensitivity vs 1-specificity and saw your link. I hope you can be of help to me in one of the issue that I am facing in generating combo chart(bar chart and plot). I am a novice and have some difficulty in getting this logic correct. I am give a dataset (I am attaching a sample dataset). I am using a barplot() and passing values for
2007 May 18
3
lapply not reading arguments from the correct environment
Hello, I am facing a problem with lapply which I ''''think''' may be a bug. This is the most basic function in which I can reproduce it: myfun <- function() { foo = data.frame(1:10,10:1) foos = list(foo) fooCollumn=2 cFoo = lapply(foos,subset,select=fooCollumn) return(cFoo) } I am building a list of dataframes, in each of which I want to keep only column
2007 Feb 22
3
List filtration
Hello R-ologists, Imagine you have a list "list" like so: >list [[1]] [1] "IPI00776145.1" "IPI00776187.1" [[2]] [1] "Something" "IPI00807764.1" "IPI00807887.1" [[3]] [1] "IPI00807764.1" [[4]] [1] "Somethingelse" What I need to achieve is a filtered list "list2" like so: >list2 [[1]] [1]
2004 Aug 13
2
lapply problem
R-help, I wish to replace NULL elements(or missing) in the following list : > z2 $cod mean sd 62.56190 12.65452 $haddock mean sd 36.61490 11.50365 $ling mean sd 86.17949 20.43587 $saithe mean sd 50.275847 5.453606 $whiting NULL $"norway pout" mean sd 13.739623 1.393104 $"great silver smelt" mean
2005 Sep 22
2
R: extracting elements in a matrix
Dear R-users For a given matrix of dimension, say (n,p), I'd like to extract for every column those elements that are bigger than twice the interquartile range of the corresponding column. Can I get these elements without using a loop? Thank you for your help Frank [[alternative HTML version deleted]]
2005 Dec 16
3
Help with data.frame and lapply
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hello: I'm having problems with this line of code: X.lm <- lapply(names(d), function(x) lm(d["cls"] ~ d[x], data=d)) d[x] is what is giving trouble here, but I don't know exactly how to solve it. What I'm trying to do is to create a linear model from each column of the data frame 'd' to apply ANOVA later. Thanks
2011 Apr 28
1
Extract complete rows by group and maximum
Hi I'm trying to extract complete rows from a dataframe by group based on the maximum in a column within that group. Thus I have a dataframe: cvd_basestudy ... es_time ... _____________ study1 ... 0.3091667 study2 ... 0.3091667 study2 ... 0.2625000 study3 ... 0.3033333 study3 ... 0.2625000 __________ etc I can extract the basestudy and the max(es_time)
2013 Jan 11
2
weird merge()
Hi, I have some protein array data, each array in a separate text file. So I read them in and try to combine them into a single data frame by using merge(). see code below (If you download the attached data files into a specific folder, the code below should work): fls<-list.files("C:\\folder_of_download",full.names=T) ## get file names prot<-list() ## a list to contain
2014 Jul 01
1
combining data from multiple read.delim() invocations.
Is there a better way to do the following? I have data in a number of tab delimited files. I am using read.delim() to read them, in a loop. I am invoking my code on Linux Fedora 20, from the BASH command line, using Rscript. The code I'm using looks like: arguments <- commandArgs(trailingOnly=TRUE); # initialize the capped_data data.frame capped_data <- data.frame(lpar="NULL",