• Register
0 votes

Problem :

I am trying to merge data in R but facing following error

error in fix.by(by.x, x) : 'by' must specify one or more columns as numbers, names or logical

6 5 3
6,930 points

1 Answer

0 votes

Solution :

If you need to merge many dataframes then please consider binding individual dataframes into a list with the lapply() after that you can run any needed calculations after that run in a Reduce(..., merge) to merge all the files of list into one the wide dataframe. Below is the correct method which processes and merges 100 files :


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)
newdata <- Reduce(function(...) merge(..., by=1, all=T), dfList)

write.table(newdata, "outputR
9 7 4
38,600 points

Related questions

1 vote
1 answer 835 views
Problem : I am very new to R programming. Currently I am learning R programming. I have below two tables I have asembled them via cbind(). My first Table table_alpha is as below: x1 col1_x1 col2_x1 A "1999 12 01 00:00" " 0.4" " 0" B "1999 12 02 00:00" " - ... = table_num[,1], fill=-9999) Please find below the error: &ldquo;Error in fix.by(by.x, x) : 'by' must specify uniquely valid columns&rdquo;.
asked Mar 28 morrisBson 3.2k points
0 votes
2 answers 833 views
Problem : I am facing below error and I am unable to understand the meaning of the error. All my variable names are correct and there are no typing errors. Does anybody faced this issue before any solution on it? My erroneous code : datNewagg <- aggregate (dataNew, by = ... mean) It gives following error : Error in aggregate.data.frame(datNew, by = list("x", "y", : arguments must have same length
asked Dec 6, 2019 alecxe 7.5k points
0 votes
1 answer 697 views
Problem : I have about 25 dataframes which are essentially the frequency counts of my elements stored in the column called Elements. They all have some of the different and some of the the same elements in my Elements columns so they just look like below : dataframe called ... on them but facing below error: Error in rbind(deparse.level, ...) : numbers of columns of arguments do not match .
asked Dec 24, 2019 alecxe 7.5k points
1 vote
1 answer 377 views
Problem: I have limited knowledge of R and ggplot. I have recently written a function and trying to run the function as shown below: ggplot(datfr, aes(x = dat1[1:951,], y = dat2[1:951,])) + geom_point() After executing above function I am facing below error: Don't ... and when I try to use nrow on my two datasets it again returns the same number of rows. How can I fix above ggplot related error.
asked May 26 Martin K 6.6k points
0 votes
1 answer 137 views
Problem: I have only the fundamental knowledge related to R. I want to simulate the very basic moving average process in R which is as shown below for your reference: x_t = Z_(t-1)-0.4Z_(t-2)+Z_t. Please find below my code in R: z = rnorm(500, 0, 1) x ... was unable to find the exact solution for my above error. I am looking for some help from R expert if possible to fix my above R related error.
asked Aug 12 Raphael Pacheco 4.9k points