Questions tagged [r-colnames]

114 questions
0
votes
0 answers

Changing column name in R

I want to change column name (from T2 [?C] to T2 [°C]) of data stored in .csv. I am using following code in R setwd("D:/Test") fs::dir_tree() dirlist <- list.files(full.names = FALSE, no.. = TRUE) dirlist read_the_files <- function(filelist){ …
0
votes
1 answer

Correctly order/sort columns based on string in colnames tidyverse style in R

This is just a slice of a large dataframe that I have dput(MyData) structure(list(Frui1_Trea4_Ty4_0d = c(10L, 4L, 28L, 147L, 6L), Frui1_Trea4_Ty4_14d = c(18L, 0L, 26L, 70L, 27L), Frui1_Trea4_Ty8_0d = c(9L, 1L, 21L, 168L, 6L),…
MEC
  • 71
  • 1
  • 10
0
votes
1 answer

R gt package - How to rename all columns at once

I have a dataframe like this one: library(gt) library(tidyverse) library(gtExtras) test = dplyr::tibble( id = 1:3, type1_value1 = 2:4, type1_value2 = 3:5, type2_value1 = 4:6, type2_value2 = 5:7) I actually want to have only spanners but…
Essi
  • 761
  • 3
  • 12
  • 22
0
votes
1 answer

How to calculate mean of only few columns of a text file in R?

I am using following code in R to calculate mean of all columns in various text files. Now, I need to modify the existing code to calculate mean of only few columns e.g. Temp [C], Press [Pa], Pow [W] etc. (All the columns in the txt file are in…
0
votes
2 answers

How to include conditional statements while reading the data in R?

Using the code mentioned below in R, I am reading the data (.txt files) saved in different folders. There are following conditions that I need to include in my code. The structure of my txt files is as follows: Date/Time XY [XY] C1 [m2] C1c C2 [m]…
0
votes
1 answer

How to resolve error 'Class attribute on column 1 of different items do not match' in R

I have various .txt files stored in multiple folders. The txt files have various columns, one of which is Temperature. Few files have temperature column name as T2 [°C] while others have it as T2 [?C]. I want to keep the temperature column name as…
0
votes
1 answer

How can I change the name of a particular column in various files in R?

I have various .txt files stored in multiple folders. The txt files have various columns, one of which is Temperature. Few initial txt files temperature column name as T2 [°C] while others have it as T2 [?C]. I want to keep the temperature column…
0
votes
2 answers

How to make conditional statement based on column titles in R

I am exporting a dataframe to R I want to set a condition so that if the column header matches any of the following name below Data_design <- c( "age", "sex", "font") Then an error is flagged in the condition if statement. For instance, if I import…
Jonatino
  • 63
  • 10
0
votes
2 answers

Subset of Columns based on the same column names

I have 2 data frames. In my dataset, a part of column name with leading zeros or trailing zeros should be ignored when matching columns, such as 009 = 9 or 22.0 == 22. And I want to subset the intersection of column names of two data frames. As an…
mashimena
  • 165
  • 6
0
votes
1 answer

Remove middle inconsistent characters from a column header column name with r

` set.seed(500) index <- sample(1:nrow(Bands_reflectance_2017),100, replace = FALSE ) Bands_reflectance_2017 <- dput(head(Bands_reflectance_2017[1:100])) Bands_reflectance_2017 <- structure( list( t2017.01.05T08.25.12.000000000_blue =…
Nangula
  • 3
  • 2
0
votes
1 answer

Assigning column name as title within for loop

I am attempting to make a plots for each column of my dataframe and pass on the column name to be the title for each plot. There are a total of 72 columns that need their own individual plot. Facet_wrap is not an appropriate solution to this…
Ethan
  • 3
  • 2
0
votes
1 answer

Replace multiple strings in column names of r

I am trying to do a string replacement for column names based on a different patterns. I want to replace one pattern with a new string and another pattern with another string, but for a number of different string patterns. As an example: I have a…
Ross
  • 5
  • 4
0
votes
1 answer

Trying to iterate through certain columns based on column name using R but columns not in list get eliminated

I have a dataframe with 50 columns. I am trying to iterate through the columns in a dataframe that contain the word "apple". The dataframe contains 24 "apple" columns. If apple_1 = 1 then all the other apple_x columns in the row should equal to 1…
0
votes
1 answer

Print columnnames as vector

My code prints a tibble as binary matrix. It prints a binary matrix if a specific stringpart is matched (with grepl). This is my output. A tibble: 11 × 6 Aufzeichnungen …
KC-Migo
  • 85
  • 4
0
votes
2 answers

R - refer to column names rather than column index when using lapply with data frame

I am using lapply to take values from specific columns of a data frame and change them from a 1-5 scale to the inverse (i.e., 1 becomes 5, 2 becomes 4). I have managed to do this by referring to the column index: df_vars[,c(104:183, 222:249,…
Dee G
  • 133
  • 9