Displaying 20 results from an estimated 10000 matches similar to: "How to refer the element in a named list?"
2009 Sep 06
2
How to figure the type of a variable?
Hi,
I want to know what is there returned values of 'lm'. 'class' and 'lm'
does not show that the returned value has the variable coefficients,
etc. I am wondering what is the command to show the detailed
information. If possible, I aslo want the lower level information. For
example, I want to show that 'coefficients' is a named list and it has
2 elements.
2009 Sep 14
3
How to refer to the last a few rows?
Hi,
x=matrix(1:60,nr=6)
I can refer the last 2 rows by
x[5:6,]
If I don't know the total number of rows is 6, is there a way to refer
the last 2 rows?
Regards,
Peng
2009 Sep 06
2
How to pop up the graphics window from Rscript?
Hi,
I am wondering how to pop up the graphics window from Rscript. I run
the following code, but I don't see the graphics window, even
transiently.
Regards,
Peng
$ Rscript plot.R
> x=1:10
> y=1:10
> plot(x,y)
>
2010 Jan 01
5
How to not to terminate read.table if the input file is empty?
read.table terminates the program if the input file is empty. Is there
way to let the program continue and return me a NULL instead of
terminating the program?
$ Rscript read_empty.R
> read.table("empty_data.txt")
Error in read.table("empty_data.txt") : no lines available in input
Execution halted
$ cat read_empty.R
read.table("empty_data.txt")
$ cat
2009 Sep 06
2
How to wait for a user response in Rscript?
Hi,
In 'example(barplot)' running in R, I see 'Hit <Return> to see next
plot:', then R waits for my input. I am wondering how to wait for a
user response in Rscript.
Regards,
Peng
2009 Sep 23
1
How to show number in the %f format?
Hi,
I have the following matrix, which is printed %e format (in C's way).
I am wondering how make it be printed in %f format (in C's way)?
Regards,
Peng
> significant_analysis_results[,7:8]
pval(ki-wt) pval(ko-wt)
Nab2 1.913348979e-06 2.731944670e-09
Rasal1 2.482254110e-05 1.054711084e-05
Ccndbp1 6.307674516e-08 2.268947934e-04
Svep1 0.000000000e+00
2011 Apr 12
1
extract element from list by rownames
Hi,
I've a list of list.
I want to extract an element by the rownames.
I can extract it by:
data[[1]][[1]][[4]][1]
But I want to exctract it by a command like this:
data[[1]][["B0"]][["smac"]][["cont"]][1]
It's possible?
Thanks,
Alfredo
> str(data)
List of 1
$ :List of 4
..$ :List of 4
.. ..$ : num [1, 1:3] 0.4 0.458 0.5
.. ..$ : num
2011 Jul 13
1
AR-GARCH with additional variable - estimation problem
Dear list members,
I am trying to estimate parameters of the AR(1)-GARCH(1,1) model. I have one
additional dummy variable for the AR(1) part.
First I wanted to do it using garchFit function (everything would be then
estimated in one step) however in the fGarch library I didn't find a way to
include an additional variable.
That would be the formula but, as said, I think it is impossible to add
2009 Aug 28
1
How to convert a string passed as an argument to a vector?
Hi,
$ cat commandArgs.R
args=commandArgs(trailingOnly=TRUE)
args[1]+10
I have the above code. But the following command line gives me an error. I
am wondering what is the correct way to convert a string to a vector?
$ Rscript commandArgs.R 1:3
> args=commandArgs(trailingOnly=TRUE)
> args[1]+10
Error in args[1] + 10 : non-numeric argument to binary operator
Execution halted
Regards,
Peng
2009 Sep 07
1
Why this statement does not print anything in an if-statement that includes 'q()'?
Hi,
I run the following script. I don't understand why the second
'length(args)' does not show anything but the first one shows '0'. Is
it because the command 'q()' affects anything in the if-statement.
However, if I change the second 'length(args)' to
'print(length(args))', the script will print the length of 'args'. Can
somebody let me know
2009 Sep 16
1
How to convert a frame to a matrix while maintaining that a number is still a number?
Hi,
See the code below.
'x' is a frame. x$C1 are all numbers 1, 2 and 3.
'as.matrix(x)' convert x$C1 to strings "1", "2" and "3". I'm wondering
how to maintain that the first column of 'as.matrix(x)' still numbers.
Regards,
Peng
$ cat read.csv
"C1","C2"
"1","x"
"2","y"
2009 Sep 22
1
How to get the current script file name in the script?
Hi,
Right now, I hardcode the file name in the script. But when I change
the script name, I have to change the file name in the script to make
sure the file name inside the script is synchronized with the script
name. I am wondering if there is an automatic way to get the script
file name in a script.
Regards,
Peng
$ Rscript get_file_name.R
> print('get_file_name.R')
[1]
2009 Sep 14
2
What are the return values of aov?
Hi,
I don't quite understand what are the return values of aov. I know
that it has 'coefficients'. But I need to know what all the other
return values are. Can somebody let me know how to figure them?
Value:
An object of class 'c("aov", "lm")' or for multiple responses of
class 'c("maov", "aov", "mlm",
2009 Sep 15
1
coefficients of aov results has less number of elements?
Hi,
I run the following commands. 'A' has 3 levels and 'B' has 4 levels.
Should there be totally 3+4 = 7 coefficients (A1, A2, A3, B1, B2, B3,
B4)?
> a=3
> b=4
> n=1000
> A = rep(sapply(1:a,function(x){rep(x,n)}),b)
> B = as.vector(sapply(sapply(1:b, function(x){rep(x,n)}), function(x){rep(x,a)}))
> Y = A + B + rnorm(a*b*n)
>
> fr =
2010 Aug 25
1
accessing the attr(*,label.table) after importing from spss
Dear all,
I just received a file from a colleague in spss. The read.spss could not finish the file due to an error (Unrecognized record type 7, subtype 18 encountered in system file) so instead I converted the file using stat-transfer. Looking at my data I see that most labels are in the attributes and I?d love to access them and assign the pertinent variables to factors without doing the whole
2009 Oct 27
2
Why I get this error? Error in close.connection(f) : invalid connection
I don't understand why I can not close 'f'. This may be very simple,
but I don't see why. Could somebody let me know?
$ cat gzfile.csv
"","V1","V2","V3","V4","V5"
"1",1,5,9,13,17
"2",2,6,10,14,18
"3",3,7,11,15,19
"4",4,8,12,16,20
$ Rscript gzfile.R
> f =
2010 Jan 21
1
How to write '"' to a csv with the default setting of write.csv?
Please see the following example. I can not write '"' to a csv file
successfully. Could somebody let me if it is possible to write '"' to
a csv file with the default setting of write.csv?
my_home$ Rscript main_quote.R
> x=rbind(
+ "\"A\""
+ , "\"B\""
+ )
> x
[,1]
[1,] "\"A\""
[2,]
2009 Aug 10
5
Example scripts for R Manual
Hi,
I am wondering if some experienced users would help put the
ready-to-run code of the examples in the manuals. It would help new
users learn R faster by putting all the examples in an ready-to-run R
script file. Can somebody help do so sometime and post the code along
with the pdf manuals?
http://cran.r-project.org/manuals.html
Regards,
Peng
2009 Sep 05
2
How to 'apply' on multiple arguments?
Hi,
I am wonder if there is a function similar 'apply' but it could accept
multiple arguments?
For example, I have the following matrix.
x=matrix(1:6,nr=2)
y=matrix(1:6,nr=2)
I want to find a function that can be used to compute the linear
regression for each pair of rows in the two matrices?
multiple_apply(x,y,1,function(u,v){lm(u ~ v)}
That is, I wound like something like the above
2010 Feb 03
5
How to export the examples in help(something) to a file?
Some examples in the help page are too long to be copied from screen.
Could somebody let me know some easy way on how to extract the example
to a file so that I can play with them?