r - How to reassign values to new rows and keep rest of values in these new rows -
this question has answer here:
first of i'm not sure if titled topic right hope description clear everything.
firstly, had data frame this
vehicle type number1 number2 "car" "truck, suv, hatchback" 2 3 "bike" "scraper, lowrider" 5 7 "plane" "bomber" 2 3
secondly, i've used great csplit
function splitstackshape
change data frame this
vehicle type1 type2 type3 number1 number2 "car" "truck" "suv" "hatchback" 2 3 "bike" "scraper" "lowrider" na 5 7 "plane" "bomber" na na 2 3
but final result see this
vehicle type number1 number2 "car" "truck" 2 3 "car" "suv" 2 3 "car" "hatchback" 2 3 "bike" "scraper" 5 7 "bike" "lowrider" 5 7 "plane" "bomber" 2 3
and have no idea how , don't know if topic describes problem enough (i have feeling package tidy may helpful). thank in advance
the default direction
wide
in csplit
. can specify direction='long'
expected output.
library(splitstackshape) csplit(df1, "type", sep=", ", "long") # vehicle type number1 number2 #1: car truck 2 3 #2: car suv 2 3 #3: car hatchback 2 3 #4: bike scraper 5 7 #5: bike lowrider 5 7 #6: plane bomber 2 3
Comments
Post a Comment