• Register
0 votes
1.3k 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 DataFrame1

Elements    freq
boby         4324234
janey        433
hamy        4324
timy         22
dataframe called DataFrame1
Elements     freq
boby          987
janey         223
jonny        12
jimy          98092

I am just trying to set up the table so that my Elements becomes my column and each row is my frequencies. This is so that I should be able to combine all my dataframes.

I have tried rbind on them but facing below error:

“Error in rbind(deparse.level, ...) : numbers of columns of arguments do not match”.

6 5 3
7,540 points

Please log in or register to answer this question.

1 Answer

0 votes

Solution :

An alternative method to the rbind + dcast technique is that the use of the tidyverse.

Please use the pipes (%>%) to first use the bind_rows() to bind all the dataframes together while simultaneously creating the dataframe id column here I just called the variable as "df". Then use the spread() to move the unique " Elements" values to become the column names and spreading your values of the "freq" across your new columns. " Elements" is the key and "freq" is your value in this case.

9 7 4
38,600 points

Related questions

0 votes
1 answer 1.2K views
1.2K 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
asked Nov 15, 2019 peterlaw 6.9k points
0 votes
1 answer 3 views
3 views
Problem: How to fix this error > R error in match.names(clabs, names(xi)) : names do not match previous names
asked 5 days ago ummeshani 8.8k points
0 votes
1 answer 13 views
13 views
Problem: I am trying to use the quantile regression forest function in R (quantregForest) which is built on Random Forest package. I am getting a type mismatch error that I can't quite figure why. it gives the following error: Error in predict.quantregForest(qrf, newdata = xtest) : Type of predictors in new data do not match types of the training data.
asked Mar 16 ummesalma 29.2k points
1 vote
1 answer 8 views
8 views
Problem: I need clear idea about How do I combine two data-frames based on two columns? I know I can use the plyr and its friends to combine dataframes, and merge as well, but so far I don't know how to merge two dataframes with multiple columns based on 2 columns?
asked Mar 10 Sabbir Hossain 14.6k points
1 vote
1 answer 48 views
48 views
Problem: From a function that will give me all Marsenne primes after I created Marsenne numbers but i got this: error: no function to return from, jumping to top level
asked Feb 24 Sofia Castro 4.2k points
0 votes
1 answer 4 views
4 views
Problem: I have new question related with this my topic deleting outlier in r with account of nominal var. In new case variables x and x1 has different lenght x <- c(-10, 1:6, 50) x1<- c(-20, 1:5, 60) z<- c(1,2,3,4,5,6,7,8) bx <- boxplot(x) bx$out bx1 ... is not help me Rsolnp: In cbind(temp, funv) : number of rows of result is not a multiple of vector length (arg 1) or i just do anything wrong.
asked 3 days ago padma1 34.3k points
0 votes
1 answer 7 views
7 views
Problem: I have been trying to fix this issue but I couldn't find the solution. I have two tables namely : user, firstdb. In user table I have two primary keys, and in the foreign key table I have one field which I want to make it a foreign key. I tried to ... . I tried to create a relationship like this in MySQL, it worked fine with me, but it doesn't work here for some reason. Any suggestions?
asked Apr 26 munim01 21k points
0 votes
1 answer 3 views
3 views
Problem: How to fix this error > Error in `[.data.frame`(x, r, vars, drop = drop) : undefined columns selected
asked 5 days ago ummeshani 8.8k points
0 votes
1 answer 1 view
1 view
Question: I keep getting this error and I'm not quite sure what it means. All of my variable names are consistent and there are no typos. Am I missing something here? The code datNewagg <- aggregate (dataNew, by = list('x', 'y', 'z', 'a', 'ab'), FUN = mean) Produces the error Error in aggregate.data.frame(datNew, by = list("x", "y", : arguments must have same length
asked Apr 23 munim01 21k points
0 votes
1 answer 8 views
8 views
Problem: Any solution for this error: Error in aggregate.data.frame(as.data.frame(x), ...) : arguments must have same length
asked Mar 14 Wafa Abu Yousef 6.1k points