Grokbase Groups R r-help October 2015
FAQ

You need to break down your expression into parts and see what the data is:


Empl[c(2,4)]
$family
$family$spouse
[1] "Fred"


$family$children
[1] 3


$family$child.ages
[1] 4 7 9




$family
$family$spouse
[1] "Mary"


$family$children
[1] 2


$family$child.ages
[1] 14 17



Empl[c(2,4)]$family #>> notice only picks the first object
$spouse
[1] "Fred"


$children
[1] 3


$child.ages
[1] 4 7 9




To get multiple objects, then you need to use some of the 'apply'
functions; in this case 'sapply':

sapply(Empl[c(2,4)], '[[', 'spouse')
family family
"Fred" "Mary"






Jim Holtman
Data Munger Guru


What is the problem that you are trying to solve?
Tell me what you want to do, not how you want to do it.


On Sun, Oct 4, 2015 at 2:31 PM, FERNANDO MANSITO CABALLERO wrote:

Dear Madam/Sir,

I am trying to understand R and I have come to a stumbling block. i
have written:
Empl <- list(employee="Anna",family=list(spouse="Fred",children=3,
+child.ages=c(4,7,9)),employee="John",family=list(spouse="Mary",children=2,
+child.ages=c(14,17)))
Empl[c(2,4)]$family$spouse
[1] "Fred"
#instead of [1] "Fred" "Mary"
Where am I wrong?

Thank you very much for your patience
Yours truly,
Fernando Mansito

[[alternative HTML version deleted]]

______________________________________________
R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

  [[alternative HTML version deleted]]

Search Discussions

Discussion Posts

Previous

Follow ups

Related Discussions

Discussion Navigation
viewthread | post
posts ‹ prev | 3 of 13 | next ›
Discussion Overview
groupr-help @
categoriesr
postedOct 4, '15 at 6:31p
activeNov 2, '15 at 12:14a
posts13
users11
websiter-project.org
irc#r

People

Translate

site design / logo © 2018 Grokbase