0

I am having a problem updating the values in a list of dataframe. My data is a large collection of different samples...so I split the dataframe according to samples and stored them in a list. I have created the necesarry columns by assigning the NA variable and then put it in a loop:

 for (part in 1:2){
  for(i in 1:length(stepss)){
    idx<-stepss[i]:(stepss[i]+ss-1)
    info_samples[[part]]$TIMESTAMP[i]<-mean(info_samples_orig[[part]]$TIMESTAMP[idx], na.rm=T)

however, I still keep on getting the same error, where the replacement row has one extra row than the data row. I have tried all sorts of debugging, but can't seem to figure out the problem.

I used the split function to seperate a large dataframe according to participant/sample names, and then updating each dataframe by running a for loop. I expect all the values to be updated, however I keep getting the error that the number of replacement rows has more than the number of data rows. My R version is 4.3.1

I Paul Roy
  • 11
  • 2
  • 1
    Welcome to SO, I Paul Roy! This is a good start at a first question, but it's a bit hard to address it without having sample data (and please not 125K rows of it). There are a few things about this code and doing what you say you want to do that are likely to do something wrong (e.g., if `ss` is negative, this code will likely do wrong things); please consider sharing sample data (e.g., using `dput`, see https://stackoverflow.com/q/5963269 , [mcve], and https://stackoverflow.com/tags/r/info) and explain what you're trying to do in case we can recommend a more efficient method. Thanks! – r2evans Aug 07 '23 at 11:40
  • Well, rather obviously, you are not counting the size of your arrays correctly. Start with a smaller sample sized input and look carefully. Another hint: send that output of `mean(info_samples_orig....` to a brand-new variable and examine it. Perhaps you're creating a row with names in it or some such? – Carl Witthoft Aug 07 '23 at 15:38
  • Hi, I did separately check the size of the arrays, and the total number of rows is checking out. Essentially, there is no data that is being added or subtracted either, the columns are just being updated. – I Paul Roy Aug 08 '23 at 11:46

0 Answers0