How to create a series of descending string in a column in data frame in R
1
0
Entering edit mode
17 months ago

Dear , I would like to create a new column in a data frame in R, where I want to have string (e.g. SNP) in a descending orders (e.g. SNPs1, SNPs2, SNPs3, etc.). Could any of you let me know how ?

R • 886 views
ADD COMMENT
0
Entering edit mode

It is difficult to see what you need without an example, you may have a look at the arrange() function : https://dplyr.tidyverse.org/reference/arrange.html

ADD REPLY
0
Entering edit mode

Thanks. Actually, this link is not what I am looking for. I want to create a new column, and I want to have value in this column that are n a descending orders (e.g. SNPs1, SNPs2, SNPs3, etc.). Example: my data frame is DF, and I want it to have a new column (here is columnX), and it should contain the characters SNP1, SNP2, SNP3, etc. like this table : enter image description here

ADD REPLY
0
Entering edit mode

Ok, please next time directly add a reproducible example in your post to make your question clear to others

ADD REPLY
2
Entering edit mode
17 months ago
zx8754 12k

We need paste:

# example data
d <- data.frame(rn = 1:3)
# d
#   rn
# 1  1
# 2  2
# 3  3

d$ColumnX <- paste0("SNP", seq_len(nrow(d)))
# d
#   rn ColumnX
# 1  1    SNP1
# 2  2    SNP2
# 3  3    SNP3
ADD COMMENT
0
Entering edit mode

Thank you, this is exactly what I need

ADD REPLY

Login before adding your answer.

Traffic: 2592 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6