Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
847 views
in Technique[技术] by (71.8m points)

how to create md5 hash of a column in R?

I have a data frame

ID, VID
 1 , xyz-0001

I would like to replace VID with md5 hash of VID column value.

How would i do that in R? I looked at digest package but can not figure out how to put that in R Code

Thanks

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Package digest absolutely suitable for this task, so firstly we load it:

library(digest)

Then create/load/etc. test data.frame df:

txt <-
"ID,VID
1,xyz-0001
2,abc-0987"

df <- read.table(header=T, text=txt, sep=",", stringsAsFactors=F)
df

The initial data looks like:

  ID      VID
1  1 xyz-0001
2  2 abc-0987

Then we can use function digest with specified algorithm:

df$VID <- sapply(df$VID, digest, algo="md5")
df

Now we have hashed column VID in df:

  ID                              VID
1  1 44e3a9cf85f802ef50f18e64e01c5e32
2  2 c576ff180b2046c1a3ae939766588fd3

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...