Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8793911
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T23:10:59+00:00 2026-06-13T23:10:59+00:00

Hi I have a quick question about converting a list of data.frames into an

  • 0

Hi I have a quick question about converting a list of data.frames into an array (I prefer the latter format for plotting and manipulation).

I have the following code which just about works but I am not getting the loop right and wondered if someone could point me to what I am doing wrong.

What I want to do is fill an array with the values of one of the columns from each of the different data.frames in my list of data.frames.

# list all the files in a directory
data.dir = "/data/output"

# list all the files to plot
files <- list.files(data.dir, full=TRUE, pattern="Fields_grid*")

# cat them together into one data frame
data <- lapply( files,  read.csv, header=FALSE, skip=26)

# calc no. of files
nfiles <- length(files)

# set up an empty array to fill with data
z <- array( NA, dim=c(length(x), length(y), nfiles ))

# loop through all the data.frames/files 
for (i in 1:length(nfiles)) {

# calc index's of lists
x <- sort(unique( data[[i]]$V3))
y <- sort(unique( data[[i]]$V4))
indx <- match( data[[i]]$V3, x)
indy <- match( data[[i]]$V4, y)

# fill array
z[ cbind( indx, indy, i)] <- data[[i]]$V5 }

I know this is a terrible question as I can not reproduce the result I get, but I hope you can understand my issue. When I look at z[,,1] this contains data but z[,,2] to z[,,nfiles] contains NA (i.e. my loop has not worked). I guess its something to do with the indexing but I really can’t see what I have done wrong.

Again apologies for an opaque question and thanks for having a look!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T23:11:00+00:00Added an answer on June 13, 2026 at 11:11 pm

    The problem is with your loop:

    for (i in 1:length(nfiles)) { [...]
    

    Here, length(nfiles) is 1 so your loop is only run for i equals 1.

    Instead, you meant to do

    for (i in 1:nfiles) { [...]
    

    or

    for (i in seq_len(nfiles)) { [...]
    

    or

    for (i in seq_along(files)) { [...]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a quick question about adding Zend_Dojo_Form into Zend_layouts. I have a Zend_Dojo_Form
A quick question about saving data in symfony 2. I have this method (just
I have a quick question about how to serve data from a repository in
Quick question about the built in python list object. Say you have a list
Quick question about data joining. Say I have some elements that each contain a
I have quick question about text parsing, for example: INPUT=a b c d e
I have a quick question about something I imagine must be pretty easy -
I have a quick question about ARC in iOS. (Sorry I've asked so many
I have a quick question about encapsulating specific types with typedef . Say I
I have a quick question about the dealloc() and viewDidUnload() methods. I notice a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.