split a variable into several new ones using R

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP

split a variable into several new ones using R



I a table where I have a variable Technology, which includes "AllRenewables", "Biomass","CSP","Offshore wind", "Onshore wind" and "Wind".



I would like that the "All Renewables" is split into "Biomass","CSP","Offshore wind", "Onshore wind" and that the "Wind" technology is split into ""Offshore wind", "Onshore wind".



I thought that would be possible with the below listed code, but it seems that in this case all the wind-entries are deleted. I don't really understand why.



If anybody could help, I would be really really thankful. Sarah


AllRenewables = c("Biomass","CSP","Offshore wind", "Onshore wind", "PV")
AllRenewablesNew = c("Biomass","CSP","Offshore wind", "Onshore wind", "PV")

df1=data.frame(Technology="All.renewables",NewTech=AllRenewablesNew)
df2=data.frame(Technology=AllRenewables,NewTech=AllRenewablesNew)
TechLookup=rbind(df1,df2)

Total.split=merge(Total,TechLookup,by="Technology")
Total$Technology=total$NewTech
Total$NewTech<-NULL

write.csv(Total.split, file="total.split.csv")`





The expected output is not clear. AllRenewables and AllRenewablesNew looks the same
– akrun
2 days ago


AllRenewables


AllRenewablesNew





yes, it is because the code is wrong. What should be is that the entry "All renewables" in the variable Technology, splits into "Biomass","CSP","Offshore wind", "Onshore wind", "PV" - replacing the entry all renewables. - so before the split the entries in the variable technology are " AllRenewables", "Biomass","CSP","Offshore wind", "Onshore wind" and "PV".
– Sarah8888
yesterday






After the split the variables should only be "Biomass","CSP","Offshore wind", "Onshore wind", "PV" - and the number in "AllRenewables" should go into "Biomass","CSP","Offshore wind", "Onshore wind", "PV" (i.e. if the entry was 1, after the split, there should stand a one in all the technologies).
– Sarah8888
yesterday









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Comments

Popular posts from this blog

Executable numpy error

Trying to Print Gridster Items to PDF without overlapping contents

Mass disable jenkins jobs