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 csplitfunction 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

Popular posts from this blog

android - Why am I getting the message 'Youractivity.java is not an activity subclass or alias' -

python - How do I create a list index that loops through integers in another list -

c# - “System.Security.Cryptography.CryptographicException: Keyset does not exist” when reading private key from remote machine -