[R] rename columns with pattern

Ivan Calandra ivan.calandra at univ-reims.fr
Mon Jan 12 15:30:57 CET 2015


Hi!

Nice example!

You just need to learn about the functions names() and paste():
names(dff)[1:6] <- paste("bp", 1:6, sep="_")

HTH,
Ivan

--
Ivan Calandra, ATER
University of Reims Champagne-Ardenne
GEGENAA - EA 3795
CREA - 2 esplanade Roland Garros
51100 Reims, France
+33(0)3 26 77 36 89
ivan.calandra at univ-reims.fr
https://www.researchgate.net/profile/Ivan_Calandra


Le 12/01/15 15:17, Kuma Raj a écrit :
> I want to rename columns 1 to 6 in the sample data set as  bp_1 to
> bp_6. How could I do that in R?
>
> Thanks
>
>> dput(dff)
> structure(list(one = c(1.00027378507871, 0.982313483915127, 1.1531279945243,
> 1.07400410677618, 1.22710472279261, 1.19762271047046, 1.10904859685147,
> 1.32060232717317), two = c(1.04707392197125, 1.00998288843258,
> 1.17598904859685, 1.09595482546201, 1.28599589322382, 1.26632675564591,
> 1.12986995208761, 1.30704654346338), three = c(1.06301619895049,
> 1.02743782797171, 1.1977093315081, 1.11466803559206, 1.2949441022131,
> 1.28365657768591, 1.1305452886151, 1.32089436459046), four = c(1.06994010951403,
> 1.03489904175222, 1.19799452429843, 1.1172022587269, 1.28742984257358,
> 1.27650013346977, 1.12265058179329, 1.30723134839151), five =
> c(1.07019712525667,
> 1.03722792607803, 1.19174811772758, 1.11514168377823, 1.26594387405886,
> 1.25720010677582, 1.11339630390144, 1.29178507871321), six = c(1.11111909650924,
> 1.08407027150354, 1.24785877253023, 1.16373032169747, 1.31150581793292,
> 1.31042514031455, 1.16205338809035, 1.37122975131189), idd = 1:8),
> .Names = c("one",
> "two", "three", "four", "five", "six", "idd"), row.names = c(NA,
> -8L), class = c("tbl_df", "data.frame"))
> ______________________________________________
> R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



More information about the R-help mailing list