2

I am working on a data frame with all variables of numeric type

summary.default(pfnew)
  • ID 6016315 -none- numeric
  • iterator 6016315 -none- numeric
  • value 6016315 -none- numeric
  • CV 6016315 -none- numeric

I want to create a pivot table grouped by iterator and CV and summarize the count of ID. In essence, I want number of points in the data frame corresponding to a particular set of iterator and CV value. The code I have used is:

Code

install.packages("tidyr")
install.packages("dplyr")
install.packages("vctrs")
library(vctrs)
library(tidyr)
library(dplyr)
allow_lossy_cast(pivot<-pfnew%>%
  select(pfnew$iterator,pfnew$CV,pfnew$ID)%>%
  summarise(CT=count(pfnew$ID)))

But as discussed in other forums even after using allow_lossy_cast, I am getting the same error message.

Error: Must subset columns with a valid subscript vector. x Can't convert from to due to loss of precision.

How can we resolve this? Or can we do the same job in any other manner?

2 Answers 2

6

I just came across the same error with a different dplyr function and realized that I included the name of the data frame after calling it. Try removing pfnew$ from select and summarise so it's select(c(iterator, CV,ID)).

2

select function throws error when you are using dataframe to call the predictors here. Try renaming the column name to a more suitable name in case it persists (using space in name will throw error if you donot use dataframe to call the predictor column, therefore avoid using spaces in your column name) and use the predictors name directly and this will resolve the issue.

Example - instead of pfnew$This is an example, use pfnew$This_Is_an_example and then directly use this name in select -

select(This_Is_an_example) %>%
....
1

Not the answer you're looking for? Browse other questions tagged or ask your own question.