Skip to main content
Filter by
Sorted by
Tagged with
1 vote
0 answers
63 views

'Error: unexpected symbol' when using rename function

I'm working on the capstone project for my Google Data Analytics certificate and I'm trying to rename the columns on 1 of my data sets to match the others in order to merge them, but I keep getting 2 ...
JA2024's user avatar
  • 11
2 votes
5 answers
80 views

How to access row and column names (year and month) from a (monthly) time series, when rownames and colnames fail?

In monthly time series (frequency = 12), R prints out the years and months automatically, arranging them to look like row names and column names. But they are not accessible through rownames or ...
dolphingang's user avatar
1 vote
4 answers
75 views

Replacing elements of column names with associated strings

I have a data.table with automatically generated column names. The names take the form: N.x.y.z Where N is a character (literally N), and the remaining variables are integers. I also have a .csv which ...
Digitalis2512's user avatar
0 votes
3 answers
45 views

create new columns based on the column names in tidyverse

My data set has columns where the variable categories are mentioned, for eg: column name is "Shrawan 2071 -Dog Bite". Here "Shrawan" is the month "2071" is a year and &...
Rakesh Chand's user avatar
0 votes
1 answer
39 views

colnames() inconsistent with name in dataframe

I have the oddest problem, it's never happened to me before and I haven't found any solution yet. I'm working on a dataframe where several columns have similar names (S1Q1.pre / S1Q1.post, S1Q2.pre/...
Vetepi's user avatar
  • 11
2 votes
2 answers
58 views

loop regression when column names have special characters

Dummy data shown below. I tried amending my loop regression code to account for spaces in the column names, but it still gives an error. Additionally, I'm not sure how to adjust .x to account for ...
sjedi's user avatar
  • 67
0 votes
2 answers
54 views

print column name when specific row of a column contains string in R

I have the following dataset A B C D 1! 0! 1! 0! 0! . 1! 1! I need to print the column name to each match as follows matches_1 matches_0 A,C B,D C,D A I'...
Gabriel G.'s user avatar
1 vote
2 answers
50 views

Ordering rows and columns of R Matrix

I have a matrix in R like this: bio1 bio10 bio11 bio12 bio13 bio14 bio15 bio16 bio17 bio18 bio19 bio2 bio3 bio4 bio5 bio6 bio7 bio8 bio9 bio1 1.00 0.90 0.91 -0.40 -0.21 -0.54 0.71 -0.22 -...
Burak Suiçmez's user avatar
2 votes
4 answers
107 views

Why does R colnames ignore the vector with specified names and only pay attention to the index?

I came across some weird behavior in R. Imagine that I have this data frame, and I want to change the names of the columns by using colnames and a vector: df <- data.frame(a = seq(1,10), b = seq(11,...
mauraeh's user avatar
  • 37
1 vote
2 answers
87 views

Merge multiple dataframes while retaining their names as column names?

I'm trying to import multiple CSV files in the RStudio while keeping their filenames. library(readr) library(dplyr) library(purrr) #importing all csv files at once csv_files = list.files(pattern =&...
Debajyoti Kabiraj's user avatar
2 votes
3 answers
124 views

cbind() - how to label a vector dynamically in one line

Consider: cbind("1" = 1:4) ## giving. 1 [1,] 1 [2,] 2 [3,] 3 [4,] 4 What I am trying to achieve is replacing "1" with a function that returns a character expression, e.g. ...
clp's user avatar
  • 1,528
1 vote
2 answers
70 views

Concatenate 2 dataframe in alternate way ( first column of first dataframe, first column of second dataframe and so on but with column names unchanged

Hello i am new to R programming and i am stuck with one problem. I would like to combine 2 dataframe into a new one in this way. First column of first dataframe, first column of second dataframe and ...
Tommaso Roncacci's user avatar
1 vote
2 answers
69 views

When is it necessary to use quotation marks to refer to a column in my dataframe and when can I do it without?

I'm fairly new in working with R, so I might not be naming so things right ;-) I would like to plot the results of three different linear models. To do so, I loop over my column names, which I saved ...
tobix100's user avatar
0 votes
1 answer
56 views

How to paste individual column names in front of column means in R?

I want to paste the names of the month in front of the monthly mean temperatures from my dataset but nothing I try works. I can't use very complex code because its for my class and we are starting ...
Lily Cowper's user avatar
1 vote
1 answer
349 views

Simple way to set R column names as index

I'm new to R and looking for an easy way to get rid of column names in a R dataframe and return the names to their index [1,2,3,4..]. Something like combining .iloc and reset_index in pandas. I need ...
Maya's user avatar
  • 13
0 votes
0 answers
50 views

how do i see all the column names in my dataset using colnames function without getting an error message?

The challenge i am facing here is that the name i used to save my dataframe cannot be found in the environment thereby making it difficult to see the column names of my dataset. this is the code am ...
Chinonyerem Okwunakwe's user avatar
0 votes
1 answer
493 views

Error of "incorrect number of dimensions" occurred when using lapply to a list of dataframes

I was dealing with a list of two dataframes. Both look this way. What I would like to do was to change the row names and column names so that they may look this way. Here is the code I used. # ...
B-WingBreaker's user avatar
0 votes
0 answers
14 views

Selecting specific matrix columns based on another matrix [duplicate]

I have a matrix with 10 columns named "PC1", "PC2" and so forth and another matrix containing certain columns names of the first matrix, which I'm supposed to extract. First matrix ...
Nedralixx's user avatar
3 votes
2 answers
286 views

Reorder matrix columns based on colnames suffix and the order of a character vector

I have a matrix that looks like this cols <- c("foo_AFG", "baz_SYR", "baz_TUR", "foo_SYR", "foo_TUR", "baz_AFG") foo <- matrix(ncol = ...
umbe1987's user avatar
  • 3,508
2 votes
2 answers
77 views

Renaming columns if a specific character string doesn't exist

I'm looking to rename colnames to include the characters _16S_sed if they're not present. For example I have the dataset > dput(dataframe1) structure(list(GL11_DN_1_16S_sed = structure(1:3, .Label =...
Geomicro's user avatar
  • 454
0 votes
1 answer
56 views

Is it possible for column names to be hyperlinks in R function gt?

Using the function gt in R, I can get hyperlinks working for cells in the table, but I can't quite figure out how to do it for column names. library(gt) library(tidyverse) make_into_links <- ...
Richard Martin's user avatar
0 votes
1 answer
30 views

How to remove all the columns for each row where Col X > 200?

I have data with various columns for say A, B, C, Cq, D, Dq, F, Fq, M, Mq, ..., X. I want that whenever column X has value > 200, that particular row for all the columns should be removed. My code ...
Michael_Brun's user avatar
0 votes
0 answers
36 views

Conditional statement in R - col C should have valid values only when col A and B have valid values

I have data with various columns and I need to use few conditional statements on the columns. I am able to write following code successfully for conditions to be applied on two columns i.e., AB and MN....
Alexia k Boston's user avatar
0 votes
0 answers
84 views

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....
Alexia k Boston's user avatar
0 votes
1 answer
82 views

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), ...
MEC's user avatar
  • 71
0 votes
1 answer
201 views

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 = ...
Essi's user avatar
  • 791
0 votes
1 answer
173 views

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] ...
Alexia k Boston's user avatar
-1 votes
1 answer
100 views

How to use values of a column in defining bounds of another column values in R?

While processing my data (txt files), I need to define a lower and upper bound for my data in a way that values in between the bounds should remain as they are, else should become NA. I am using ...
Michael_Brun's user avatar
0 votes
2 answers
244 views

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 ...
Alexia k Boston's user avatar
0 votes
1 answer
877 views

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]....
Alexia k Boston's user avatar
0 votes
1 answer
49 views

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 ...
Alexia k Boston's user avatar
0 votes
2 answers
121 views

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") ...
Jonatino's user avatar
1 vote
2 answers
63 views

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 ...
mashimena's user avatar
  • 175
0 votes
1 answer
58 views

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( ...
Nangula's user avatar
0 votes
1 answer
103 views

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. ...
Ethan's user avatar
  • 3
1 vote
2 answers
387 views

Compare the column names of multiple CSV files in R

I'm combining 12 CSV files into one dataframe in R. Before doing this I want to ensure all the column names are an exact match with each other. I've made a dataframe where each column is the column ...
Michael Thompson's user avatar
1 vote
1 answer
296 views

How to use current column name in lapply function in R?

I have two data sets: The first data set contains participants' numerical answers to questions: data <- data.frame(Q1 = 1:5, Q2 = rev(1:5), Q3 = c(4, 5, 1, 2, ...
user20291515's user avatar
0 votes
1 answer
680 views

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 ...
Ross's user avatar
  • 5
1 vote
1 answer
152 views

R dataframe has date as part of a column name and I want specify the most recent two columns without typing them each time

I am trying to automate a report that I am running manually each week. I have a data frame called p_wide where each week a new column is being added and column names contain dates that represent when ...
tokay's user avatar
  • 13
2 votes
1 answer
730 views

R user function column name selection with or without quotes

I want to be able to enter a column name of a tibble in a user function with or without using quotation marks. Using myfunc function below I can enter the column name, but I can't encapsulate it ...
Andrew's user avatar
  • 149
0 votes
1 answer
54 views

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 = ...
Steinunn Sigurjónsdóttir's user avatar
0 votes
1 answer
52 views

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's user avatar
  • 95
0 votes
2 answers
883 views

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 ...
Dee G's user avatar
  • 155
0 votes
2 answers
1k views

How do I stop r from using the first row of data as the column name?

I'm extremely new to using R and I keep running into an issue with my current data set. The data set consists of several txt files with 30 rows and 3 columns of numerical data. However, when I try to ...
Psych's user avatar
  • 3
0 votes
1 answer
312 views

Add suffix to some columns in 1st dataframe based on values in 2 columns in 2nd dataframe

Task1: I want to add a suffix to some columns in the 1st dataframe based on the values in 2 columns in a second dataframe. My psuedocode would be: if (dict.df$source == 'cre' or dict.df$source == '...
seehorse's user avatar
2 votes
1 answer
89 views

Is there a way to name column names or rownames?

, , RE Midterm Final mean A 81.9 75.1 78.5 B 78.3 69.2 73.8 C 79.6 74.4 77.0 mean 79.9 72.9 76.4 I'm trying to name the rows and columns so that "Subject" is ...
redwoods's user avatar
1 vote
1 answer
3k views

Is there a way to specify flextable header labels by just listing the new header names in order?

I'm using flextable with a dataset that has many columns, and I want to use set_header_labels() to change them all at once, in order, without having to specify which name goes with each specific value....
J.Sabree's user avatar
  • 2,482
-1 votes
1 answer
593 views

Renaming Columns with index with a For Loop in R

I am writing this post to ask for some advice for looping code to rename columns by index. I have a data set that has scale item columns positioned next to each other. Unfortunately, they are oddly ...
JFC_Mx's user avatar
  • 23
1 vote
2 answers
848 views

R : Change name of variable using for loop

I have a data, and vectors conatin name of variables, from these vectorsi calculate the sum of variables contained in the vector and i want to put the result in a new variables that have diffrent ...
Reda's user avatar
  • 497
1 vote
1 answer
1k views

Change column names of data frames stored in a list by condition

I have a list with several data frames of different taxa. The df's for the different taxa are of different length and have different names for columns with the "same information", e.g. "...
Tobias Richter's user avatar