Not sure how to ask this, but i’ll give it a try:
I have 20 data.frames (e.g. 2006_1, 2006_2, 2007_1, 2007_2, …) that I imported from MS Access.
Each data.frame has 10 columns and approximately 3 millions rows.
The first column in each data.frame is named secuityName, which is a list of stock tickers followed by some tags.
I would like to upcase every row in the SecurityName column in every one of the 20 data.frames.
The structure follows:
2006_1
> **SecurityName** **...**
> AAPL abcdef **...**
> MSFT abcdef **...**
2006_2
> **SecurityName** **...**
> AAPL abcdef **...**
> MSFT abcdef **...**
I would like each one to look like this:
2006_1
> **SecurityName** **...**
> AAPL ABCDEF **...**
> MSFT ABCDEF **...**
I have a vector named *Raw_data_vector* that has all the data.frame names
Raw_data_vector
> 2006_1
> 2006_2
> 2007_1
> 2007_2
> ...
I have tried to use lapply but can’t get it to work:
lapply(1:length(Raw_data_vector), function(x) toupper(get(x)[,1]),Raw_data_vector)
This should get you started. I used
data.framesthat have characters that start their names so I don’t wind up with any funny business.Per the comments:
Depending on the names of your data.frames, you’ll need to alter the
patternargument tols. Also, R doesn’t change things in place (for the most part) instead it creates a new one.You are seeing it as output to the console because it isn’t assigned to anything! Instead use something like
out <- llply(ls(...)...). Then inspectout. It will be a list of the data frames you supplied with their additional column. You can inspectRobjects with?str.Finally, this list of objects notion is a common result when working with many similar (or identical) things. It is easy from here to continue doing whatever process you want, accept instead of calling
function(data.frame)in something like a for loop, you can calllapply(list of data frames, function)… Clear as mud to be sure.
If you must do the lowercase operation to the existing data.frame, you can use the always scary
assignfunction:now look at your data.frames.