1

I am trying to isolate one point in the same location (same column and row) from 1000 data frames. Each data frame has the same 8 columns with varying amounts of rows (at least one)- and I only need the points from the first row for now. These data frames are within a list created with the lapply function. Here is how I did that:

list <- list.files(pattern=".aei")
files <- lapply(list, read.table, ...)

Now, I need to isolate points from each data frame in Row 1 and Column 2. I was able to do this for one data frame with the following code:

a <- data.frame(files[1])[1,2]

However, I can't get this to work for all 1000 files. I've tried several pieces of code, such as:

all <- data.frame(files[1:999])[1,2]
all<- lapply(files data.frame)[1,2]
all<- lapply(files, data.frame[1,2])

and even two different for loops:

for(i in files [[1:999]]) {
    list(files[1:999])[1,2]
}
for(i in files [[1:999]]) {
    data.frame(files[1:999])[1,2]
}

Are any of these methods on the right track or are they completely wrong? I've been stuck on this for awhile and seem to have hit a complete dead end regarding any other ideas. Please let me know of any suggestions you may have!

sarwoz
  • 13
  • 2
  • 2
    Please make the question more [reproducible](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example). – NelsonGon Jun 06 '19 at 05:21

1 Answers1

2

We can use a anonymous function (lambda function) to extrac the element

lapply(files, function(x) x[1,2])

The read.table already gives a data.frame, so there is no need to wrap with data.frame

akrun
  • 874,273
  • 37
  • 540
  • 662