How do I change every element in a vector to my reference class?How to access the last value in a vector?Test if a vector contains a given elementCounting the number of elements with the values of x in a vectorHow to find common elements from multiple vectors?Extract every nth element of a vectorIs there an R function for finding the index of an element in a vector?Is there a way to declare public and private methods for S4 Reference Classes?How to remove last n characters from every element in the R vectorChanging every element in vector or list by the same numberHow to implement a dispose pattern into a reference class in R?
Count the occurrence of each unique word in the file
Are the IPv6 address space and IPv4 address space completely disjoint?
why `nmap 192.168.1.97` returns less services than `nmap 127.0.0.1`?
What if a revenant (monster) gains fire resistance?
Is it possible to have a strip of cold climate in the middle of a planet?
2.8 Why are collections grayed out? How can I open them?
What should you do if you miss a job interview (deliberately)?
The screen of my macbook suddenly broken down how can I do to recover
Loading commands from file
On a tidally locked planet, would time be quantized?
Why Shazam when there is already Superman?
How much character growth crosses the line into breaking the character
How can Trident be so inexpensive? Will it orbit Triton or just do a (slow) flyby?
Yosemite Fire Rings - What to Expect?
Is it safe to use olive oil to clean the ear wax?
Create all possible words using a set or letters
Removing files under particular conditions (number of files, file age)
Can I sign legal documents with a smiley face?
What should you do when eye contact makes your subordinate uncomfortable?
Aragorn's "guise" in the Orthanc Stone
Why did the Mercure fail?
How to bake one texture for one mesh with multiple textures blender 2.8
How can "mimic phobia" be cured or prevented?
What is this called? Old film camera viewer?
How do I change every element in a vector to my reference class?
How to access the last value in a vector?Test if a vector contains a given elementCounting the number of elements with the values of x in a vectorHow to find common elements from multiple vectors?Extract every nth element of a vectorIs there an R function for finding the index of an element in a vector?Is there a way to declare public and private methods for S4 Reference Classes?How to remove last n characters from every element in the R vectorChanging every element in vector or list by the same numberHow to implement a dispose pattern into a reference class in R?
I am trying to convert every object in my vector of strings to a reference class. Suppose my reference class is:
myrefclass <- function(str)
methods <- list()
methods$cnt <- function()
return(str_length(str))
methods
I tried to convert the following vectors (albeit, no success):
v1 <- c("ABC", "D", "FGHI")
v2 <- c(ABC="ABC", D="D", FGHI="FGHI")
Then I try to apply the reference class to each element of the vector:
res1 <- sapply(v1, myrefclass)
res2 <- sapply(v2, myrefclass)
I would then think I could use this as follows (but regretfully it doesn't work):
> res1["ABC"]$cnt
NULL
> res2["ABC"]$cnt
NULL
How do I create a vector of reference classes and access its methods?
NOTE #1: I would prefer a base-R solution but it would be interesting to
see what packages might help
NOTE #2: I am looking for a dynamic solution. To illustrate that point,
suppose an extension of this question would be to useres1
orres2
to find all strings that have$cnt=3
. Therefore, accessing strings
as inres1$ABC$cnt
won't work as you don't know thatABC
is in
v1
orv2
(whichever you think is appropriate).
r
add a comment |
I am trying to convert every object in my vector of strings to a reference class. Suppose my reference class is:
myrefclass <- function(str)
methods <- list()
methods$cnt <- function()
return(str_length(str))
methods
I tried to convert the following vectors (albeit, no success):
v1 <- c("ABC", "D", "FGHI")
v2 <- c(ABC="ABC", D="D", FGHI="FGHI")
Then I try to apply the reference class to each element of the vector:
res1 <- sapply(v1, myrefclass)
res2 <- sapply(v2, myrefclass)
I would then think I could use this as follows (but regretfully it doesn't work):
> res1["ABC"]$cnt
NULL
> res2["ABC"]$cnt
NULL
How do I create a vector of reference classes and access its methods?
NOTE #1: I would prefer a base-R solution but it would be interesting to
see what packages might help
NOTE #2: I am looking for a dynamic solution. To illustrate that point,
suppose an extension of this question would be to useres1
orres2
to find all strings that have$cnt=3
. Therefore, accessing strings
as inres1$ABC$cnt
won't work as you don't know thatABC
is in
v1
orv2
(whichever you think is appropriate).
r
If you want the number of characters, usenchar
.
– yarnabrina
2 days ago
For clarification, you wantres1["ABC"]$cnt=3
andres1["FGHI"]$cnt=4
. Is that it?
– yarnabrina
2 days ago
yes, that's exactly what I would like to achieve
– Denis
2 days ago
add a comment |
I am trying to convert every object in my vector of strings to a reference class. Suppose my reference class is:
myrefclass <- function(str)
methods <- list()
methods$cnt <- function()
return(str_length(str))
methods
I tried to convert the following vectors (albeit, no success):
v1 <- c("ABC", "D", "FGHI")
v2 <- c(ABC="ABC", D="D", FGHI="FGHI")
Then I try to apply the reference class to each element of the vector:
res1 <- sapply(v1, myrefclass)
res2 <- sapply(v2, myrefclass)
I would then think I could use this as follows (but regretfully it doesn't work):
> res1["ABC"]$cnt
NULL
> res2["ABC"]$cnt
NULL
How do I create a vector of reference classes and access its methods?
NOTE #1: I would prefer a base-R solution but it would be interesting to
see what packages might help
NOTE #2: I am looking for a dynamic solution. To illustrate that point,
suppose an extension of this question would be to useres1
orres2
to find all strings that have$cnt=3
. Therefore, accessing strings
as inres1$ABC$cnt
won't work as you don't know thatABC
is in
v1
orv2
(whichever you think is appropriate).
r
I am trying to convert every object in my vector of strings to a reference class. Suppose my reference class is:
myrefclass <- function(str)
methods <- list()
methods$cnt <- function()
return(str_length(str))
methods
I tried to convert the following vectors (albeit, no success):
v1 <- c("ABC", "D", "FGHI")
v2 <- c(ABC="ABC", D="D", FGHI="FGHI")
Then I try to apply the reference class to each element of the vector:
res1 <- sapply(v1, myrefclass)
res2 <- sapply(v2, myrefclass)
I would then think I could use this as follows (but regretfully it doesn't work):
> res1["ABC"]$cnt
NULL
> res2["ABC"]$cnt
NULL
How do I create a vector of reference classes and access its methods?
NOTE #1: I would prefer a base-R solution but it would be interesting to
see what packages might help
NOTE #2: I am looking for a dynamic solution. To illustrate that point,
suppose an extension of this question would be to useres1
orres2
to find all strings that have$cnt=3
. Therefore, accessing strings
as inres1$ABC$cnt
won't work as you don't know thatABC
is in
v1
orv2
(whichever you think is appropriate).
r
r
edited 2 days ago
Denis
asked 2 days ago
DenisDenis
5,873957118
5,873957118
If you want the number of characters, usenchar
.
– yarnabrina
2 days ago
For clarification, you wantres1["ABC"]$cnt=3
andres1["FGHI"]$cnt=4
. Is that it?
– yarnabrina
2 days ago
yes, that's exactly what I would like to achieve
– Denis
2 days ago
add a comment |
If you want the number of characters, usenchar
.
– yarnabrina
2 days ago
For clarification, you wantres1["ABC"]$cnt=3
andres1["FGHI"]$cnt=4
. Is that it?
– yarnabrina
2 days ago
yes, that's exactly what I would like to achieve
– Denis
2 days ago
If you want the number of characters, use
nchar
.– yarnabrina
2 days ago
If you want the number of characters, use
nchar
.– yarnabrina
2 days ago
For clarification, you want
res1["ABC"]$cnt=3
and res1["FGHI"]$cnt=4
. Is that it?– yarnabrina
2 days ago
For clarification, you want
res1["ABC"]$cnt=3
and res1["FGHI"]$cnt=4
. Is that it?– yarnabrina
2 days ago
yes, that's exactly what I would like to achieve
– Denis
2 days ago
yes, that's exactly what I would like to achieve
– Denis
2 days ago
add a comment |
0
active
oldest
votes
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55280695%2fhow-do-i-change-every-element-in-a-vector-to-my-reference-class%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
0
active
oldest
votes
0
active
oldest
votes
active
oldest
votes
active
oldest
votes
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55280695%2fhow-do-i-change-every-element-in-a-vector-to-my-reference-class%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
If you want the number of characters, use
nchar
.– yarnabrina
2 days ago
For clarification, you want
res1["ABC"]$cnt=3
andres1["FGHI"]$cnt=4
. Is that it?– yarnabrina
2 days ago
yes, that's exactly what I would like to achieve
– Denis
2 days ago