• Register
0 votes

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 I I keep getting the constant error from R. I am the very beginner to the R, How can I fix the below error

Error in sort.int(x, na.last = na.last, decreasing = decreasing, ...) : 'x' must be atomic”.

8 4 2
2,300 points

Please log in or register to answer this question.

2 Answers

0 votes

Solution :

I have read your problem, I can understand that you are learning the new technology so you are experiencing the errors while executing your code.

I think the problem is that your list may be containing only one element. And your call to sort() is now trying to sort the list and not the single element.

I can suggest you two simple solutions:

To sort your values in a element of your list, you can use

head(sort(var_sal[[1]], decreasing=TRUE), 3) 

Here a [[1]] is selecting the very first element of your list and then sorting your values within it.

Or you can create var_sal explicitly as the numeric vector instead:

var_sal <- (irs_data[13]/irs_data[12])[[1]]
5 2 1
4,980 points
0 votes


The problem is that salary_var is a list containing a single-element. The call to sort() is then trying to sort a list, not an atomic element. You can see that salary_var is a list by running str(salary_var). If you omit the c(), you'll instead end up with a data frame with a single column, which gives the same problem.

Two simple solutions:

To sort the values in the element of the list, use
head(sort(salary_var[[1]], decreasing=TRUE), 3)

where the [[1]] selects the first element of the list and sorts the values within it.

Alternatively, create salary_var explicitly as a numeric vector instead:

salary_var <- (irs_data[13]/irs_data[12])[[1]]

One note: in your post, you wrote new_var instead of salary_var in your call to sort() which may confuse other readers.

you can use the unlist() to convert the list to a vector as the sort() function takes vector form for sorting. so just use

head(sort(unlist(new_var), decreasing=TRUE), 3)

From the output of str(cc2), the variable inside of the data.table, V1, is itself a list. This means that cc2 is a nested list of length 1. The error is occurring because table calls sort.list, which requires an atomic vector as input.

Try using unlist:

cc3 <- as.data.frame(table(unlist(cc2)))

unlist will (recursively) extract elements from their list containers. So unlist(cc2) will return a vector, which works directly with table.

10 6 4
31,120 points

Related questions

0 votes
1 answer 66 views
0 votes
1 answer 94 views
0 votes
2 answers 143 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
0 votes
1 answer 225 views
How to convert non-finite calues to integer?
asked Sep 22, 2020 Daniel Anderson 4k points
0 votes
1 answer 462 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
1 answer 2.8K views
Problem : While I am trying to run the boxcox transformation with the following code urban1 <- subset(ski,urban <= 4,na.rm=TRUE) ski$gender <- as.numeric((as.character(ski$gender)),na.rm=TRUE) urban1 <- as.numeric((as.character(urban1))) a <- (ski$gender*urban1) ... -> boxcar -> boxcar.formula -> lm -> lm.fit Execution halted Please let me know if anyone knows the solution for this error message.
asked Nov 27, 2019 alecxe 7.5k points
1 vote
1 answer 1.8K views
Problem : I want to perform a logistic regression but I am facing following error I am unable to find my mistake. summary(glm(prefmerkel~angst+crisismerkel+leadership+trustworthiness+ideology+pid+agegroups+gender+region,data=gles)) Error in glm.fit(x = c(1, 1, 1, 1, 1, 1, 1, ... In Ops.factor(eta, offset) : -' nicht sinnvoll für Faktoren 3: In Ops.factor(y, mu) : -' nicht sinnvoll für Faktoren
asked Nov 24, 2019 alecxe 7.5k points
0 votes
1 answer 1.2K views
Problem : Suppose I have data.frame a And I am using following code m.fit <- lm(col2 ~ col3 * col4, na.action = na.exclude) Here the col2 has some NA values And col3,col4 have values less than 1. I am getting following error: Error in lm.fit ... because of the NAs. Problem with this warning is interpreted by every google results is pointing towards the NA values. Have I misinterpreted the error ?
asked Nov 22, 2019 peterlaw 6.9k points
1 vote
1 answer 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
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