I have the following csv data myData:
name attribute
1 Name1 attr11,attr12,attr13
2 Name2 attr21
3 Name3 attr31,attr32
I want to plot the distribution of the number of attributes, to do that I need to loop through each row, and tokenize the data in the column attribute, and count the length. Essentially, that should give a vector or another data with the same length as the original myData
I have tried:
num_attr <- length(as.list(strsplit(myData$attribute, ","))) #this just returns 3
and:
num_attr <- as.list(strsplit(myData$attribute, ","))
this returns a list something like:
["attr11" "attr12" "attr13", "attr21", "attr31" "attr32"]
I am also thinking of using apply(), like apply(myData, 1, func) but I am not sure what func to put in.
In summary, how do I plot the distribution/density of the number of attributes?