Dear all,
I would like to replace 1,2,3,4,5,6 in the first column of this tibble by the following characters :
1->FR15038
2->FR15039
3->FR15043
4->FR15045
5->FR15046
6->FR15049
Does anyone have an idea on how to do this ? The tibble is called "Diff".
Many thanks again for your help
Marie-Laure
those numbers are not 'in' your tibble. they are just part of the pretty print function that reports which number row you are looking at.
but it sounds like you want to add a character column at the start containing the names of the other columns. I suppose that makes sense so long as your data starts out with square dimensions.
library(tidyverse)
(myiris<-iris[1:4,1:4])
# Sepal.Length Sepal.Width Petal.Length Petal.Width
# 1 5.1 3.5 1.4 0.2
# 2 4.9 3.0 1.4 0.2
# 3 4.7 3.2 1.3 0.2
# 4 4.6 3.1 1.5 0.2
(myiris$names_col <- names(myiris))
# [1] "Sepal.Length" "Sepal.Width" "Petal.Length" "Petal.Width"
(myiris<- select(myiris,
names_col, everything()))
# names_col Sepal.Length Sepal.Width Petal.Length Petal.Width
# Sepal.Length 5.1 3.5 1.4 0.2
# Sepal.Width 4.9 3.0 1.4 0.2
# Petal.Length 4.7 3.2 1.3 0.2
# Petal.Width 4.6 3.1 1.5 0.2
1 Like
Thanks nirgrahamuk ! you solved my issue very quickly !
@nirgrahamuk , do you know by chance how I could change the header "names_col" by "code_station" ? Thanks again !
@nirgrahamuk , just found a solution !
colnames(Diff)
Diff <- Diff %>% rename(code_station = names_col)
Diff
Thanks again !
system
Closed
May 2, 2020, 4:25pm
6
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.