Questions tagged [names]

"names" (plural) is an attribute of some R objects in the R language

In the scientific software R for statistical computing and graphics, "names" is an attribute of some data objects, like vectors (including lists) and data frames. See ?names for details.

873 questions
212
votes
12 answers

Access lapply index names inside FUN

Is there a way to get the list index name in my lapply() function? n = names(mylist) lapply(mylist, function(list.elem) { cat("What is the name of this list element?\n" }) I asked before if it's possible to preserve the index names in the lapply()…
Robert Kubrick
  • 8,413
  • 13
  • 59
  • 91
90
votes
10 answers

R: losing column names when adding rows to an empty data frame

I am just starting with R and encountered a strange behaviour: when inserting the first row in an empty data frame, the original column names get lost. example: a<-data.frame(one = numeric(0), two = numeric(0)) a #[1] one two #<0 rows> (or 0-length…
cdmihai
  • 3,008
  • 2
  • 20
  • 18
80
votes
6 answers

Access and preserve list names in lapply function

I need to access list names inside the lapply function. I've found some threads online where it's said I should iterate through the names of the list to be able to fetch each list element name in my function: > n = names(mylist) > mynewlist =…
Robert Kubrick
  • 8,413
  • 13
  • 59
  • 91
65
votes
1 answer

Get the column names of a python numpy ndarray

Let's say I have a data file called data.txt that looks like: TIME FX FY FZ 0 10 5 6 1 2 4 7 2 5 2 6 ... In Python run: import numpy as np myData = np.genfromtxt("data.txt", names=True) >>> print myData["TIME"] [0, 1, 2] The names…
mcragun
  • 1,198
  • 3
  • 10
  • 17
65
votes
11 answers

use first row data as column names in r

I have a dirty dataset that I could not read it with header = T. After I read and clean it, I would like to use the now first row data as the column name. I tried multiple methods on Stack Overflow without success. What could be the problem? The…
sstww
  • 659
  • 1
  • 5
  • 5
62
votes
10 answers

What are all of the allowable characters for people's names?

There are the standard A-Z, a-z characters, but also there are hyphens, em dashes, quotes, etc. Plus, there are all of the international characters, like umlauts, etc. So, for an English-based system, what's the complete set? What about sets for…
Paul W Homer
  • 2,728
  • 1
  • 19
  • 25
53
votes
2 answers

How to use reference variables by character string in a formula?

In the minimal example below, I am trying to use the values of a character string vars in a regression formula. However, I am only able to pass the string of variable names ("v2+v3+v4") to the formula, not the real meaning of this string (e.g., "v2"…
Eric Green
  • 7,385
  • 11
  • 56
  • 102
51
votes
5 answers

assign headers based on existing row in dataframe in R

After transforming a dataframe, I would like to assign heads/names to the columns based on an existing row. My headers are currently: row.names X2 X3 X4 X5 X6 X7 X8 X9 ... I would like to get rid of that and use the following row as…
user3166363
  • 765
  • 2
  • 7
  • 7
46
votes
4 answers

Specifying column names in a data.frame changes spaces to "."

Let's say I have a data.frame, like so: x <- c(1:10,1:10,1:10,1:10,1:10,1:10,1:10,1:10,1:10,1:10) df <- data.frame("Label 1"=x,"Label 2"=rnorm(100)) head(df,3) returns: Label.1 Label.2 1 1 1.9825458 2 2 -0.4515584 3 3 …
Brandon Bertelsen
  • 43,807
  • 34
  • 160
  • 255
45
votes
4 answers

Can lists be created that name themselves based on input object names?

It would be very helpful to me to be able to create an R list object without having to specify the names of each element. For example: a1 <- 1 a2 <- 20 a3 <- 1:20 b <- list(a1,a2,a3, inherit.name=TRUE) > b [[a1]] [1] 1 [[a2]] [1] 20 [[a3]] [1]…
Francis Smart
  • 3,875
  • 6
  • 32
  • 58
44
votes
2 answers

How to pass dynamic column names in dplyr into custom function?

I have a dataset with the following structure: Classes ‘tbl_df’ and 'data.frame': 10 obs. of 7 variables: $ GdeName : chr "Aeugst am Albis" "Aeugst am Albis" "Aeugst am Albis" "Aeugst am Albis" ... $ Partei : chr "BDP" "CSP" "CVP" "EDU"…
grssnbchr
  • 2,877
  • 7
  • 37
  • 71
43
votes
4 answers

what is the difference between names and colnames

I just want to understand if there is a difference between names and colnames when working with data.frame. Both seems to behave the same way. Can I subsitute one by the other?
Manu H
  • 523
  • 1
  • 5
  • 17
41
votes
1 answer

Naming list elements in R

I've been doing some work with some large, complex lists lately and I've seen some behaviour which was surprising (to me, at least), mainly to do with assigning names to a list. A simple example: Fil <- list( a = list(A=seq(1, 5, 1), B=rnorm(5),…
RobertMyles
  • 2,673
  • 3
  • 30
  • 45
35
votes
2 answers

appending to a list with dynamic names

I have a list in R: a <- list(n1 = "hi", n2 = "hello") I would like to append to this named list but the names must be dynamic. That is, they are created from a string (for example: paste("another","name",sep="_") I tried doing this, which does…
Alex
  • 19,533
  • 37
  • 126
  • 195
32
votes
3 answers

What is a nested name specifier?

Related to this I want to know what exactly is a nested name specifier? I looked up in the draft but I could understand the grammar as I haven't taken any Compiler Design classes yet. void S(){} struct S{ S(){cout << 1;} void f(){} static…
Glenn
  • 321
  • 1
  • 3
  • 3
1
2 3
58 59