Saturday 15 June 2013

r - Create several dummy variables from one string variable -


I have tried a lot of things, but I think everybody is not getting results. This is my problem:

I have such a data frame, each teacher works with each grade:

  & gt; Profs & lt; - data.frame (teaches = c ("first", "first, second", "second, third", "first, second, third")); Profs 1 1 2 1, 2 3 seconds, 3 4 1, 2, 3  

I'm looking for solutions to break the variable in columns, Like:

  teaches1st teaches2nd teaches3rd 1 1 0 0 2 1 1 0 3 1 1 4 1 1 1  

contains splitstackshape < I should do the code / library and apparently degraded concat.split.expanded function in a way that gives the interpreter the interpretation. However, I can not reach the same results:

  & gt; Seek Fahirlle in default (Minimum (VCC), Max (VCC)): By 'NA' can not be NAY or END,  

By using cSplit Which I previously explained to "first concat.split * functions", I get this:

  & gt; Csplit (Profess, "teaches") teaches_1 teaches_2 teachhes_3 1: 1 NA 2 NA 2: 1 2 3 4 3 3 2 3 4 3 4 4 1 1 2 3 3  

I try That's CSplit and each one of those parameters help and tweaking, but I can not find that split. I appreciate your help.

Since your concatenated data containntated character strings (not a normalized value of a security)

function The default setting for numeric values ​​is, so there is an error about , so you need to add type = "character" to make the function work.

nan and so on.

Naming has been made more consistent with other small forms of other functions of the same family. Thus, it is now cSplit_e (though the old function name will still work).

  Library (SplitStacksSpace) cSplit_e (profess, "teaches", "," type = "character", emphasizes = 0) # teaches_1st teaches_2nd teaches_3rd # 1 1 1 0 0 # 2 1 , 2 1 1 0 # 3 seconds, 3 1 1 1 # 4 1, 2, 3 1 1 1  

? The help page for concat.split.expanded is similar to cSplit_e . If you have any tips to make it clear to understand, please raise an issue on the Geethebah page of the package.


No comments:

Post a Comment