names

use first row data as column names in r

拟墨画扇 提交于 2019-12-02 23:28:21
This should be such an easy problem but I have trouble with. 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 stackoverflow without success. What could be the problem? The dataset t1 should look like this after clean up: V1 V2 V3 V4 V5 1 col1 col2 col3 col4 2 row1 2 4 5 56 3 row2 74 74 3 534 4 row3 865 768 8 7 5 row4 68 86 65 87 I tried: colnames(t1)=t1[1,] . Nothing happens. I tried: names(t1)=ti[1,] , Nothing happens. I tried: lapply(t1, function(x) {names(x)<

Java Dynamic Names

女生的网名这么多〃 提交于 2019-12-02 21:33:16
问题 I know, that Java doesn't have a pre-processor, so some stuff is more or less impossible in java. Is there really NO way to fill those arrays with dynamic names in a loop? I'd like to have something like: for(int i=0;i<5;i++){ earnTvs[i]=(TextView) findViewById(R.id.INSERT_GREAT_TRICK_HERE("earn"+i+"Tv")); } instead of earnTvs[0] = (TextView) findViewById(R.id.earn1Tv); earnTvs[1] = (TextView) findViewById(R.id.earn2Tv); earnTvs[2] = (TextView) findViewById(R.id.earn3Tv); earnTvs[3] =

Using syntactically difficult strings as column names in a data frame

家住魔仙堡 提交于 2019-12-02 17:07:30
问题 I'm working with a data frame similar to the extract below: df <- data.frame(A=c("Some messy string to be used",222,0), B=c("Very important ? indicator from 2001", 888, 44), C=c("001 This variable / makes no sense", 888, 44), D=c("Geography", 1, 2)) I would like to use values in first row as column names, I'm using the code below: names(df) <- make.names(df[1,]) Unfortunately, the syntax generates names in the format Xn , as illustrated below: > names(df) [1] "X3" "X3" "X1" "X3" I understand

Using syntactically difficult strings as column names in a data frame

冷暖自知 提交于 2019-12-02 07:59:11
I'm working with a data frame similar to the extract below: df <- data.frame(A=c("Some messy string to be used",222,0), B=c("Very important ? indicator from 2001", 888, 44), C=c("001 This variable / makes no sense", 888, 44), D=c("Geography", 1, 2)) I would like to use values in first row as column names, I'm using the code below: names(df) <- make.names(df[1,]) Unfortunately, the syntax generates names in the format Xn , as illustrated below: > names(df) [1] "X3" "X3" "X1" "X3" I understand that the utilised strings are to messy for make.names to be meaningfully converted. How can I force R

Prevent variable name getting mangled by read.csv/read.table?

限于喜欢 提交于 2019-12-02 05:52:46
My data set testdata has 2 variables named PWGTP and AGEP The data are in a .csv file. When I do: > head(testdata) The variables show up as ï..PWGTP AGEP 23 55 26 56 24 45 22 51 25 54 23 35 So, for some reason, R is reading PWGTP as ï..PWGTP . No biggie. HOWEVER, when I use some function to refer to the variable ï..PWGTP , I get the message: Error: id variables not found in data: ï..PWGTP Similarly, when I use some function to refer to the variable PWGTP , I get the message: Error: id variables not found in data: PWGTP 2 Questions: Is there anything I should be doing to the source file to

php for loop variable names

青春壹個敷衍的年華 提交于 2019-12-02 00:01:11
问题 i got a code of 100-200 rules for making a table. but the whole time is happening the same. i got a variable $xm3, then i make a column . next row, i got $xm2 and make column. next row, i got $xm1 and make column. so my variables are going to $xm3, $xm2, $xm1, $xm0, $xp1, $xp2, $xp3. is there a way to make a forloop so i can fill $xm and after that a value from the for loop? 回答1: In this kind of structure you'd be better off using an array for these kinds of values, but if you want to make a

Select the name of a certain value in a table (e.g. max)

落花浮王杯 提交于 2019-12-01 21:19:53
问题 I have a vector of numbers. Let's call it mydata : str(mydata) # num [1:236] 2 1 1 2 2 1 2 1 2 2 ... I can then count each value using table : table(mydata) # mydata # 1 2 9 10 # 20 200 14 2 Now, I want to select the value with the highest count (in this case, "2"). I can find the highest count (e.g. 200 in this case) by using the max function: max(table(mydata)) . But how to get the name associated with the max count in the table, i.e. "2"? 回答1: A table is very much like a list or a data

Select the name of a certain value in a table (e.g. max)

大兔子大兔子 提交于 2019-12-01 21:08:56
I have a vector of numbers. Let's call it mydata : str(mydata) # num [1:236] 2 1 1 2 2 1 2 1 2 2 ... I can then count each value using table : table(mydata) # mydata # 1 2 9 10 # 20 200 14 2 Now, I want to select the value with the highest count (in this case, "2"). I can find the highest count (e.g. 200 in this case) by using the max function: max(table(mydata)) . But how to get the name associated with the max count in the table, i.e. "2"? A table is very much like a list or a data frame, in that it has values and names (attributes) that are accessible through vector subsetting. > mydata <-

How to prevent name caching and detect bluetooth name changes on discovery

独自空忆成欢 提交于 2019-12-01 01:47:28
I'm writing an Android app which receives information from a Bluetooth device. Our client has suggested that the Bluetooth device (which they produce) will change its name depending on certain conditions - for the simplest example its name will sometimes be "xxx-ON" and sometimes "xxx-OFF". My app is just supposed to seek this BT transmitter (I use BluetoothAdapter.startDiscovery() ) and do different things depending on the name it finds. I am NOT pairing with the Bluetooth device (though I suppose it might be possible, the app is supposed to eventually work with multiple Android devices and

At least the first 31 or 63 characters of an internal name are significant? [closed]

一个人想着一个人 提交于 2019-12-01 01:43:25
Here's a direct quote from the Book (K&R, 2nd ed, p. 35): "At least the first 31 characters of an internal name are significant. For function names and external variables, the number may be less than 31, because external names may be used by assemblers and loaders over which the language has no control. For external names, the standard guarantees only for 6 characters and a single case." And in C99 there is no length limitation on its internal names, but only the first 63 are guaranteed to be significant (§5.2.4.1 Translation Limits). My question is why are these limits specifically 31 or 63 ?