Hi everyone.
I have a dataset of 200 rows. I want to make a new column category from the other column which has information of different machines ,like wheel loaders , buses, cranes.
For example Wheel loaders should be with category loaders, crane equipment to cranes catergory ,So I can plot the graph based on category. Is it possible to do .
What is the rule to map from the AssetNumber to the category?
To get the count of the Open jobs category wise(equipment).Below are the variables
"Asset.Number" (L-554, repeating 5 times in asset number column).
"Work.Order" (ABC344 )
"Asset.Description (Wheel Loader 8.5 T)
I understand that you are saying there is a column called Asset.Description that contains the category plus some other information. It might be possible to extract the category from that column. We would need to know if there is a pattern to that column. Is the category always a single word that will appear only if it is the correct category? That is, if the code finds the word Loader, then the object belongs to the Loader category and there are never cases where both Loader and Crane appear in the Asset.Description?
If you provide a data set with the Asset.Description column and a complete set of the categories, someone could try to write the code to extract the category information. A simple way to post data is to copy and paste the output of a command like
dput(head(DF, 50))
where DF is that name of the data frame holding your data and the number 50 determines the number of rows selected from the start of the data. Paste the output in a response to this thread and place lines with three back ticks just before and after the output, like this
```
Paste your output here
```
Don't forget to also provide the list of categories.
Category:
Pipe Loaders
Cranes
Buses
Ambulance
Compressors
Bucket Loaders
Forklifts
Generators
Light Towers
Skid Loader
Stacker
Tractor Head
Water Tanker
Welding Machine
Posting an image of data is much less helpful than posting the output of dput because it requires others to manually enter your data. I invented a tiny set of data to test my code.
library(dplyr)
library(stringr)
DF <- data.frame(Asset.Description=c("Big Crane","Skid Loader 567",
"341T Water Tanker"))
DF <- DF |> mutate(Category=case_when(
str_detect(Asset.Description, "Pipe Loader") ~ "Pipe Loaders",
str_detect(Asset.Description, "Crane") ~ "Cranes",
str_detect(Asset.Description, "Bus") ~ "Buses",
str_detect(Asset.Description, "Ambulance") ~ "Ambulance",
str_detect(Asset.Description, "Compressor") ~ "Compressors",
str_detect(Asset.Description, "Bucket Loader") ~ "Bucket Loaders",
str_detect(Asset.Description, "Forklift") ~ "Forklifts",
str_detect(Asset.Description, "Generator") ~ "Generatorss",
str_detect(Asset.Description, "Light Tower") ~ "Light Towers",
str_detect(Asset.Description, "Skid Loader") ~ "Skid Loaders",
str_detect(Asset.Description, "Stacker") ~ "Stacker",
str_detect(Asset.Description, "Tractor Head") ~ "Tractor Head",
str_detect(Asset.Description, "Water Tanker") ~ "Water Tanker",
str_detect(Asset.Description, "Welding Machine") ~ "Welding Machine",)
)
DF
#> Asset.Description Category
#> 1 Big Crane Cranes
#> 2 Skid Loader 567 Skid Loaders
#> 3 341T Water Tanker Water Tanker
Created on 2022-01-27 by the reprex package (v2.0.1)
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.