Questions tagged [r-colnames]
114 questions
0
votes
2 answers
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 work with them in r, it automatically makes the…

Psych
- 3
- 1
0
votes
1 answer
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 == 'cre1') then append dict$timing to select column…

seehorse
- 53
- 5
0
votes
1 answer
How to rename a column of a dataframe within a function in R?
I am trying to write a function in R, but I'm struggling on how to get the input of the arguments of the function and how to change it within the function itself.
For example:
# Create dataframe
df <- data.frame(1:10, 1:10, 1:10, 1:10)
colnames(df)…
user16841962
0
votes
1 answer
Why are my column names not changing when I set the colnames in DT datable and giving me an error that ' names in the 'escape' argument not found'?
I want to change how my column names are displayed in my R Shiny App's datable, but I do not want to change how R responds to them under the hood. When I try using datatable's colnames argument, I get the following error:
Warning: Error in…

J.Sabree
- 2,280
- 19
- 48
0
votes
2 answers
Beginner using pipes
I am a beginner and I'm trying to find the most efficient way to change the name of the first column for many CSV files that I will be creating. Once I have created the CSV files, I am loading them into R as follows:
data <-…

Dodo
- 17
- 3
0
votes
1 answer
R pass column names to a function not as string
I am trying to pass column names to the following function.
unnest_dt <- function(tbl, ...) {
tbl <- as.data.table(tbl)
col <- ensyms(...)
clnms <- syms(setdiff(colnames(tbl), as.character(col)))
tbl <- as.data.table(tbl)
tbl <-…

stump
- 85
- 1
- 6
0
votes
2 answers
Renaming entries of a list within a list, by using a vector containing the column names
My data looks as follows:
DT1 <- structure(list(Province = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2,
2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, 3), Year = c(2000,
2000, 2000, 2001, 2001, 2001, 2002, 2002, 2002, 2000, 2000, 2000,
2001, 2001, 2001,…

Tom
- 2,173
- 1
- 17
- 44
0
votes
2 answers
R: How to use info from column name to modify whole column in a df
I have a df, I would like to create a function which read and modify a whole column if the columnnname contains a specific characteristica, eg. '(str)'. If the columnname contains '(str)' I would like "'%" and "%'" to be pasted before and after the…

Mette
- 315
- 1
- 3
- 12
0
votes
1 answer
assign items from list of lists as column names for data frames
I have several data frames without variables names. They are all different. I have a list with set of column names that go with each data frame (similar names for list items as data frames that match). I want to assign/use the column names on the…

Keith Wiley
- 31
- 3
0
votes
1 answer
why is the column name not changing using select or colnames?
I try to copy a column within a dataframe. Next I try to rename the columnname in the code below although I do not succeed.
library(dplyr)
d <- data.frame(red=1:3, green=4:6, yellow=7:9)
for (q in 1:3) {
d$color <- select(d, q)
…

user2165379
- 445
- 4
- 20
0
votes
2 answers
Change column name every nth column in R
So I have created a data.frame that has n columns like so:
df <- as.data.frame(matrix(nrow = 3, ncol = 15))
It looks like this:
V1 V2 V3 V4 V5 V6 V7 V8 V9 V10 V11 V12 V13 V14 V15
1 NA NA NA NA NA NA NA NA NA NA NA NA NA NA NA
2 NA NA NA NA…

QuMiVe
- 137
- 9
0
votes
1 answer
How to fit Generalized Additive Model with gam() where always all columns are used as predictors (no hard coding part in model fitting)
I have a train data table in R, which always have different columns, for example now the data table has the following column names:
library(mgcv)
dt.train <- c("DE", "DEWind", "DESolar", "DEConsumption", "DETemperature",
"DENuclear",…

MikiK
- 398
- 6
- 19
0
votes
1 answer
Replace certain colnames in a list of data frames
I have a list of data frames and I want to replace column names that start with "..." with the name of the column before.
So the starting point is as follows:
df1 <- data.frame(Tree=c(1:3), Sea=c(4:6), ...3=c(2:4), Beach=c(1:3),…

ZayzayR
- 183
- 9
0
votes
1 answer
R show data from matrix/ dataframe but not the column or row names
I have a matrix in r (or dataframe) and would like to display the data but without the column names.
This because the data contained will be part of a markdown to word and therefore only data that I have within the table is relevant.
The final…

Jo Costa
- 421
- 1
- 6
- 17
0
votes
1 answer
Change column names' dtype from float to string?
I recently got this error while trying to put my data into tensorflow format:
Error in py_call_impl(callable, dots$args, dots$keywords) :
ValueError: column_name: age vocabulary dtype must be string or integer. dtype: .
Is there…

Emma
- 31
- 5