search for: juliosergio

Displaying 20 results from an estimated 21 matches for "juliosergio".

2011 Nov 17
3
Named rows in a table (data frame) read from a file
I read a table as follows: > F1 <- read.table("Rtext3.txt") > F1 Price Floor Area Rooms Age Cent.heat a 52.00 111 830 5 6.2 no b 54.75 128 710 5 7.5 no c 57.50 101 1000 5 4.2 no d 57.50 131 690 6 8.8 no e 59.75 93 900 5 1.9 yes As it is seen, the rows have a name. However I don't know how to access a
2011 Nov 10
5
Named components in a list
I'm studying lists and I came to an example where > L $name [1] "Fred" $wife [1] "Mary" $no.children [1] 4 $child.ages [1] 4 7 9 then following the instructions to extend the list with a new component, I executed: > L[5] <-list(NewName="something") and the new list I got was: > L $name [1] "Fred" $wife [1] "Mary"
2011 Nov 08
4
Intervals in function cut
When I was studying the function cut I found this example: > x <- rep(0:8, tx0) > x [1] 0 0 0 0 0 0 0 0 0 1 1 1 1 2 2 2 2 2 2 3 3 3 3 3 4 4 4 5 5 5 5 5 5 5 5 5 5 6 [39] 6 6 6 6 7 7 7 8 8 8 8 8 > cut(x, b = 8) [1] (-0.008,0.994] (-0.008,0.994] (-0.008,0.994] (-0.008,0.994] (-0.008,0.994] [6] (-0.008,0.994] (-0.008,0.994] (-0.008,0.994] (-0.008,0.994] (0.994,2] [11] (0.994,2]
2013 Apr 16
6
I don't understand the 'order' function
I thought I've understood the 'order' function, using simple examples like: order(c(5,4,-2)) [1] 3 2 1 However, I arrived to the following example: order(c(2465, 2255, 2085, 1545, 1335, 1210, 920, 210, 210, 505, 1045)) [1] 8 9 10 7 11 6 5 4 3 2 1 and I was completely perplexed! Shouldn't the output vector be 11 10 9 8 7 6 4 1 2 3 5 ? Do I have a damaged
2013 Dec 06
2
Using assign with mapply
I have a data frame whose first colum contains the names of the variables and whose second colum contains the values to assign to them: : kkk <- data.frame(vars=c("var1", "var2", "var3"), vals=c(10, 20, 30), stringsAsFactors=F) If I do : assign(kkk$vars[1], kkk$vals[1]) it works : var1 [1] 10 However, if I try with mapply
2012 Mar 30
4
Trying to understand factors
I'm trying to figure out about factors, however the on-line documentation is rather sparse. I guess, factors are intended for grouping arrays members into categories, which R names "Levels". And so we have: * state <- c("tas", "sa", "qld", "nsw", "nsw", "nt", "wa", "wa",
2012 Mar 09
3
Interacting with the Operating System
Is there any way to issue operating system commands and geting back the results, in R? I mean, for instance, in Linux, to execute from R the 'ls' command and getting back a list of files in the current directory, or, equivalently, in Windows/DOS, the 'dir' command? I'm not interested in the 'ls' or 'dir' commands it is just an example. Do you have any
2012 Mar 10
2
Reading text files from other languages
I'm trying to read a data file that contains characters from the Spanish language: > Station <- read.fwf("LosDatos.txt",widths=c(7,7,25,8,8,5),header=FALSE, + skip=3,n=separ[1]-4) Then the R interpreter issues the following message: Error en substring(x, first, last) : invalid multibyte string at '<d1>A, S.' Calls: read.fwf ->
2012 Jun 13
1
Reading several tables from stdin
I'm trying to write a Rscript program capable of reading several tables from the standard input. The problem is that the tables aren't in files because they are coming from another process that is generating them. From the R-console the following works pretty well: |> f <- stdin() |> t <- read.table(f) |> t2 <- read.table(f) |> t uno dos 01 3 4
2013 Feb 08
2
Coercing of types when raising a number to a series of powers
I'm trying to produce a series of powers of a number as follows: |> 0.05^0:5 [1] 1 2 3 4 5 This is not the result I expected. I guess some kind of coercion happened, since, |> class(0.05^0:5) [1] "integer" Could anyone explain me what is happening here? Thanks, -Sergio.
2012 Apr 05
4
A kind of set operation in R
I have an ordered "set" of numbers, represented by a vector, say > X <- c(10:13, 17,18) > X [1] 10 11 12 13 17 18 then I have a "sub-set" of X, say > Y <- c(11,12,17,18) Is there a simple way in R to have a logical vector (parallel to X) indicating what elements of X are in Y, i.e., > Inclusion [1] FALSE TRUE TRUE FALSE TRUE TRUE I'm
2012 Mar 29
4
Handling functions as objects
I learnt that functions can be handled as objects, the same way the variables are. So, the following is perfectly valid: > f = function(a, b) { + print(a) + print(b) + } > > f1 = function(foo) { + foo(1,2) + } > > f1(f) [1] 1 [1] 2 > I also know that operators are functions, so, I can call: > '+'(1,2) [1] 3 > However, when I want to pass the
2012 Sep 12
4
Trying to use pipes in R
Hi, I'm trying to use pipes in R. By now, I could launch the linux command "wc" (to count words from a text), but I don't know how to capture the results, say in a vector of chars... Here is the R code I'm trying: :> f <- pipe("wc", open="w") :> writeLines(c("uno dos tres", "cuatro cinco", "seis"), f) :> close(f)
2012 Apr 01
2
A function like sum but with functions other than '+'
Because I didn't find in R any functions similar to the function 'reduce' from Python, I'm writing a function "freduce" as follows: freduce <- function(f, vec, ValIni=NULL, StopIn=NULL) { # f: is any function that takes two arguments of the same type # vec: is a vector of n values accepted by 'f' # # Initially f starts with ValIni, if it's given
2013 Apr 12
1
A strange behaviour in the graphical function "curve"
I thought the curve function was a very flexible way to draw functions. So I could plot funtions like the following: # I created a function to produce functions, for instance: fp <- function(m,b) function(x) sin(x) + m*x + b # So I can produce a function like this ff <- fp(-0.08, 0.2) ff(1.5) # Is the same as executing sin(1.5) - 0.08*1.5 + 0.2 # Let's plot this
2012 Aug 20
5
Some kind of inverse of "names"
I wonder if there exists some kind of inverse of the "names" primitive in R. Let me explain what do I mean: If I create a list: -> li <- list(a=1, b=2, c=3, d=4) then I can have: -> names(li) [1] "a" "b" "c" "d" which is, I guess, some kind of vector, since -> typeof(names(li)) [1] "character" however, I haven't
2012 Mar 25
2
avoiding for loops
I have data that looks like this: > df1 group id 1 red A 2 red B 3 red C 4 blue D 5 blue E 6 blue F I want a list of the groups containing vectors with the ids. I am avoiding subset(), as it is only recommended for interactive use. Here's what I have so far: df1 <- data.frame(group=c("red", "red", "red", "blue",
2012 Aug 07
0
Trying to build up a user interface with the R tcltk package
I'm trying to build up a user inteface using the R tcltk component. Since the documentation for this R library is scarce and poor, I have decided to use only the .Tcl function to pass commands to the tcl interpreter. So I wrote my first very simple tcltk program, hoping to run it from inside R and get the nice Tk window, with the following R instruction: -> .Tcl('source
2013 Apr 03
1
ploting several functions on the same plot
I want to superimpose two functions plots in the same page. The functions L0 and L1, defined below f0 <- function(mu, xm, ds, n) { 1 - pnorm((xm-mu)/(ds/sqrt(n))) } f1 <- function(mu,n) f0(mu, 386.8, 48, n) L0 <- function(mu) f1(mu, 36) plot(L0,ylim=c(0,1),xlim=c(360,420)) L1 <- function(mu) f1(mu,100) lines(L1) The plot of L0 works pretty well. However, when
2014 Jan 10
0
R strange behaviour when working with fifos
I'm trying to establish a connection to a pair of fifos in R, one represents the input stream of a process and the other one the output of the same process. The problem is that R behaves very different when running the commands directly in the interpreter than when running via a script file. Here is the script #! /usr/bin/Rscript --vanilla # The fifos (fifo1 and fifo2) were previously