Merging data - Error in fix.by(by.x, x)

前端 未结 2 1248
故里飘歌
故里飘歌 2021-01-07 07:36

I am trying to merge data in R as suggested in an answer to my other post here. Yet, I have an error.

First let me explain what I try to do. I have

2条回答
  •  自闭症患者
    2021-01-07 08:15

    Google returns this as the first listing for the R error, Error in fix.by(by.x, x) and I found it interesting no answer attempted a loop solution of the OP's very long command listing.

    For future readers needing to merge many dataframes, consider binding individual dataframes into a list with lapply(), run any needed calculations, and then run a Reduce(..., merge) to merge all files of list into one wide dataframe. Below processes and merges all 100 files of original posting:

    library(zoo)
    
    dfList <- lapply(c(1:100), function(i) {
       df <- read.table(paste0("rundata  ", i), sep= " ", col.names=c("tm","score","current"))  
       df <- df[!is.na(df$tm),]
       df$score <- zoo::na.locf(df$score)
       colnames(df) <- paste0(colnames(df), i)
       return(df)
    })
    
    newdata <- Reduce(function(...) merge(..., by=1, all=T), dfList)
    
    write.table(newdata, "outputR")
    

提交回复
热议问题