• Register
0 votes
757 views

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

Please log in or register to answer this question.

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 :

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
 
 
9 7 4
38,600 points

Related questions

1 vote
1 answer 1.4K views
1.4K 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, 2020 morrisBson 3.2k points
0 votes
2 answers 1.3K views
1.3K 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 1.1K views
1.1K 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 769 views
769 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, 2020 Martin K 6.6k points
0 votes
1 answer 484 views
484 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, 2020 Raphael Pacheco 4.9k points
0 votes
2 answers 892 views
892 views
Problem : I am trying to do some practice on the broom package in R. I ran the below code : kclusts <- data.frame(k=1:9) %>% group_by(k) %>% do(fit=kmeans(data.frame, .$k)) But I have received the below error: Error in as.vector(x, mode) : ... type 'any' I wanted to know whether I am missing something in my above string. Does anyone have the solution on this issue which I am facing currently?
asked Dec 21, 2019 alecxe 7.5k points
0 votes
1 answer 99 views
0 votes
1 answer 75 views
0 votes
2 answers 407 views
407 views
Problem : I am trying to do data manipulation using R. I am trying to import the file which is having headings and also numbers in the multiple columns. I am trying to divide my values in the one column by the other column and then trying to determine the highest values. But ... below error &ldquo;Error in sort.int(x, na.last = na.last, decreasing = decreasing, ...) : 'x' must be atomic&rdquo;.
asked Feb 17, 2020 mphil 2.3k points
0 votes
2 answers 146 views
146 views
Problem : I am stuck because of following weired error error in sort.list(y) : 'x' must be atomic for 'sort.list' have you called 'sort' on a list?
asked Nov 15, 2019 peterlaw 6.9k points