Error in gsub("'", "'", html_tbl) : input string 1 is invalid

Hello! Fairly new to using this program and having bit of trouble and receiving the following error.

Error in gsub("'", "'", html_tbl) : input string 1 is invalid

Not sure how to go back fixing this, if anybody has any ideas, I would appreciate it. Thanks!

Welcome to the forum.

I think we need to see your code and some sample data. See
FAQ Asking Questions

A handy way to supply some sample data is the dput() function. In the case of a large dataset something like dput(head(mydata, 100)) should supply the data we need. Just do dput(mydata) where mydata is your data. Copy the output and paste it here between
```

```

Below is the code and I've attached a screenshot as well for the output, I'm receiving.

segdat<-read.csv(file="wahoo_clustdat_jan23.csv")

segdatc1<-segdat%>%filter(Q109_1=="Sample")

set.seed(123)

segment_dat<-segdatc1[,57:79]

segment_dat$mean=rowMeans(segment_dat)

segment_mcdat<-data.matrix(segment_dat[,1:23]-segment_dat$mean)

gdist<-get_dist(segment_mcdat,method = "manhattan")

wss <- function(k) {
km<-kmeans(gdist, k, nstart = 30, iter.max=500)

km$tot.withinss/km$betweenss

}

k.values <- 2:8

wss_values <- map_dbl(k.values, wss)

plot(k.values, wss_values,
type="b", pch = 19, frame = FALSE,
xlab="Number of clusters K",
ylab="Total within-between clusters variance")

kopt<-kmeans(gdist,centers=3,nstart=25)
cluster<-kopt$cluster

segdatc=cbind(segdatc1,cluster)

write.csv(segdatc,file="wahoo_segments_clustmem_cust_jan23.csv")

meansbyseg<-table(segdatc$cluster)

l<-t(segdatc%>%group_by(cluster)%>%summarise(across(Q1_1:Q2_12, mean)))

meansbyseg<-rbind(meansbyseg,l[-1,])

cnames<-c("cluster1","cluster2","cluster3")

colnames(meansbyseg)=cnames

rownames<-read.csv(file="rownames.csv")
meansbyseg<-cbind(meansbyseg,rownames)

seg_palette <- col_numeric(c("#FEF0D9", "#990000"), domain = c(1, 6), alpha = 0.75)

gt(meansbyseg,rowname_col = "rownames") %>%
tab_header(
title = "Means of Questions by Cluster") %>%
fmt_number(columns = c(cluster1,cluster2,cluster3),decimals = 2) %>%
data_color(columns = c(cluster1,cluster2,cluster3),colors = seg_palette)

Without some sample data it looks like it is going to be very difficult to find the problem.

Can you supply us with some data from segment_dat

Do

dput(head(segment_dat, 100) 

And copy and paste the output here.

Thanks

1 Like

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.