0
votes
data_different_tech_count <- data_different_tech %>% 
                                 group_by(tech) %>% 
                                 summarise(count(tech))

now this gives me a data.frame as an output but I am unable to save the file. When I try to change the colnames, it shows me:

colnames(data1)[c(1,2)]<- c("tech","count")

Error in colnames<-(*tmp*, value = c("tech", "count")) : 'names' attribute [2] must be the same length as the vector [1]

When I am using

colnames(data_different_count_tech)

It says that I have only one column. When I am using the

summary(data_different_count_tech)

it shows two columns.

When I am trying to write this file to my directory it returns the following error.

write.csv(file=data_different_tech_count,"tech.csv")

Error in matrix(unlist(value, recursive = FALSE, use.names = FALSE), nrow = nr, : length of 'dimnames' [2] not equal to array extent

1
I think you need summarise (count = n ()). But you haven't named the variable you've created, and I'm not sure how dplyr will handle that.Benjamin

1 Answers

0
votes

Are you trying to get a count of the number of times each value of tech appears? I can't get your example to work without having a reproducible example.

If so, here are a few alternatives that will give you what you want:

Using Dplyr

data_different_tech_count <- data_different_tech %>% group_by(tech) %>% summarise(count = n())

Using Base R

data_different_tech_count <- as.data.frame(table(data_different_tech$tech)) 
colnames(data_different_tech_count) <- c("tech","count")