128 questions
1
vote
0
answers
91
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 ...
1
vote
4
answers
78
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 ...
0
votes
1
answer
42
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/...
0
votes
2
answers
62
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'...
2
votes
4
answers
137
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,...
2
votes
3
answers
135
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.
...
1
vote
2
answers
72
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 ...
1
vote
1
answer
580
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 ...
0
votes
1
answer
730
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.
# ...
3
votes
2
answers
363
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 = ...
0
votes
1
answer
67
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 <- ...
0
votes
0
answers
40
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....
0
votes
1
answer
130
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), ...
0
votes
1
answer
195
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] ...
0
votes
2
answers
337
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 ...
0
votes
1
answer
55
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 ...
1
vote
2
answers
71
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 ...
0
votes
1
answer
121
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. ...
1
vote
1
answer
376
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, ...
1
vote
1
answer
195
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 ...
0
votes
1
answer
59
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 = ...
0
votes
2
answers
1k
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 ...
0
votes
1
answer
320
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 == '...
1
vote
1
answer
4k
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....
1
vote
2
answers
923
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 ...