Skip to content

Instantly share code, notes, and snippets.

@andilabs
Last active December 21, 2015 20:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andilabs/6364047 to your computer and use it in GitHub Desktop.
Save andilabs/6364047 to your computer and use it in GitHub Desktop.
R
s="{'#JJ': 121, '#NN': 938, '#DT': 184, '#VB': 338, '#RB': 52}"
r1<-sapply(strsplit(s, "[^0-9_]+",as.numeric),as.numeric)
r2<-sapply(strsplit(s, "[^A-Z]+",as.numeric),as.character)
d<-data.frame(id=r2,value=r1)
r1
[,1]
[1,] NA
[2,] 121
[3,] 938
[4,] 184
[5,] 338
[6,] 52
r2
[,1]
[1,] ""
[2,] "JJ"
[3,] "NN"
[4,] "DT"
[5,] "VB"
[6,] "RB"
> class(r1)
[1] "matrix"
d
id value
1 NA
2 JJ 121
3 NN 938
4 DT 184
5 VB 338
6 RB 52
class(d)
[1] "data.frame"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment