Error message with spread()

38 views
Skip to first unread message

Dawn Ng

unread,
Jan 9, 2018, 9:22:04 AM1/9/18
to manipulatr

> spread(Client_ENT_subset, Client_ENT_subset$Transaction_Type, Client_ENT_subset$Transaction_Qty, convert = TRUE)
Error in Math.factor(var) : ‘abs’ not meaningful for factors

Can someone explain the above error message and how can I overcome it?

Dave Childers

unread,
Jan 9, 2018, 9:50:15 AM1/9/18
to Dawn Ng, manipulatr
Hi Dawn,

Try again after remove the "$" indexing from within the spread() function.

> spread(Client_ENT_subset, Transaction_Type, Transaction_Qty, convert = TRUE)

spread (like many other tidyverse functions) automatically looks inside the data frame (in your case Client_ENT_subset) to find the columns.

Dave

--
You received this message because you are subscribed to the Google Groups "manipulatr" group.
To unsubscribe from this group and stop receiving emails from it, send an email to manipulatr+unsubscribe@googlegroups.com.
To post to this group, send email to manip...@googlegroups.com.
Visit this group at https://groups.google.com/group/manipulatr.
For more options, visit https://groups.google.com/d/optout.

Dawn Ng

unread,
Jan 9, 2018, 10:35:01 AM1/9/18
to manipulatr
Hi Dave
Thanks for your advice.  It has solved my first error but now I have a different error which result in my data frame not being "spread"

> spread(Client_ENT_subset, Transaction_Type, Transaction_Qty)
Error: Duplicate identifiers for rows (303671, 303673, 303674, 303676, 303678, 303679, 303681, 303683, 303684, 303686, 303687, 303688, 303691, 303693, 303694, 303695, 303696, 303699, 303701, 303703, 303704, 303705, 303707), (304273, 304275, 304277, 304279,.....(some 100+ more rows)

Is there a way to suppress duplicates so that the "spread" function can be completed?

Thanks
Dawn

On Tuesday, January 9, 2018 at 10:50:15 PM UTC+8, Dave Childers wrote:
Hi Dawn,

Try again after remove the "$" indexing from within the spread() function.

> spread(Client_ENT_subset, Transaction_Type, Transaction_Qty, convert = TRUE)

spread (like many other tidyverse functions) automatically looks inside the data frame (in your case Client_ENT_subset) to find the columns.

Dave
On Tue, Jan 9, 2018 at 9:22 AM, Dawn Ng <dawn...@gmail.com> wrote:

> spread(Client_ENT_subset, Client_ENT_subset$Transaction_Type, Client_ENT_subset$Transaction_Qty, convert = TRUE)
Error in Math.factor(var) : ‘abs’ not meaningful for factors

Can someone explain the above error message and how can I overcome it?

--
You received this message because you are subscribed to the Google Groups "manipulatr" group.
To unsubscribe from this group and stop receiving emails from it, send an email to manipulatr+...@googlegroups.com.

Dave Childers

unread,
Jan 9, 2018, 10:42:42 AM1/9/18
to Dawn Ng, manipulatr
That typically happens when the variables do not uniquely identify the rows. One workaround is to do something like:

Client_ENT_subset <- Client_ENT_subset %>% mutate(id = row_number()) 

before spread().


To unsubscribe from this group and stop receiving emails from it, send an email to manipulatr+unsubscribe@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages